Skip to content

Commit e17d8c8

Browse files
committed
feat(test): test mypyc_attr(supports_weakref=True)
1 parent 4fe1dba commit e17d8c8

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
@@ -1408,3 +1408,45 @@ class TestOverload:
14081408

14091409
def __mypyc_generator_helper__(self, x: Any) -> Any:
14101410
return x
1411+
1412+
[case testMypycAttrSupportsWeakref]
1413+
import weakref
1414+
from mypy_extensions import mypyc_attr
1415+
1416+
@mypyc_attr(supports_weakref=True)
1417+
class WeakrefClass:
1418+
pass
1419+
1420+
obj = WeakrefClass()
1421+
ref = weakref.ref(obj)
1422+
assert ref() is obj
1423+
1424+
[case testMypycAttrSupportsWeakrefInheritance]
1425+
import weakref
1426+
from mypy_extensions import mypyc_attr
1427+
1428+
@mypyc_attr(supports_weakref=True)
1429+
class WeakrefClass:
1430+
pass
1431+
1432+
class WeakrefInheritor(WeakrefClass):
1433+
pass
1434+
1435+
obj = WeakrefInheritor()
1436+
ref = weakref.ref(obj)
1437+
assert ref() is obj
1438+
1439+
[case testMypycAttrSupportsWeakrefSubclass]
1440+
import weakref
1441+
from mypy_extensions import mypyc_attr
1442+
1443+
class NativeClass:
1444+
pass
1445+
1446+
@mypyc_attr(supports_weakref=True)
1447+
class WeakrefSubclass(NativeClass):
1448+
pass
1449+
1450+
obj = WeakrefSubclass()
1451+
ref = weakref.ref(obj)
1452+
assert ref() is obj

0 commit comments

Comments
 (0)