Skip to content

Commit 7da4e53

Browse files
feat(test): test mypyc_attr(supports_weakref=True)
1 parent a116ab1 commit 7da4e53

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

mypyc/test-data/irbuild-classes.test

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,3 +1381,45 @@ class M(type): # E: Inheriting from most builtin types is unimplemented
13811381
@mypyc_attr(native_class=True)
13821382
class A(metaclass=M): # E: Class is marked as native_class=True but it can't be a native class. Classes with a metaclass other than ABCMeta, TypingMeta or GenericMeta can't be native classes.
13831383
pass
1384+
1385+
[case testMypycAttrSupportsWeakref]
1386+
import weakref
1387+
from mypy_extensions import mypyc_attr
1388+
1389+
@mypyc_attr(supports_weakref=True)
1390+
class WeakrefClass:
1391+
pass
1392+
1393+
obj = WeakrefClass()
1394+
ref = weakref.ref(obj)
1395+
assert ref() is obj
1396+
1397+
[case testMypycAttrSupportsWeakrefInheritance]
1398+
import weakref
1399+
from mypy_extensions import mypyc_attr
1400+
1401+
@mypyc_attr(supports_weakref=True)
1402+
class WeakrefClass:
1403+
pass
1404+
1405+
class WeakrefInheritor(WeakrefClass):
1406+
pass
1407+
1408+
obj = WeakrefInheritor()
1409+
ref = weakref.ref(obj)
1410+
assert ref() is obj
1411+
1412+
[case testMypycAttrSupportsWeakrefSubclass]
1413+
import weakref
1414+
from mypy_extensions import mypyc_attr
1415+
1416+
class NativeClass:
1417+
pass
1418+
1419+
@mypyc_attr(supports_weakref=True)
1420+
class WeakrefSubclass(NativeClass):
1421+
pass
1422+
1423+
obj = WeakrefSubclass()
1424+
ref = weakref.ref(obj)
1425+
assert ref() is obj

0 commit comments

Comments
 (0)