55from weakref import proxy, ref
66from mypy_extensions import mypyc_attr
77from testutil import assertRaises
8+ from typing import Optional
89
910@mypyc_attr(native_class=False)
1011class Object:
@@ -15,22 +16,22 @@ class Object:
1516_callback_called_cache = {"ref": False, "proxy": False}
1617
1718def test_weakref_ref() -> None:
18- obj: Object | None = Object()
19+ obj: Optional[ Object] = Object()
1920 r = ref(obj)
2021 assert r() is obj
2122 obj = None
2223 assert r() is None, r()
2324
2425def test_weakref_ref_with_callback() -> None:
25- obj: Object | None = Object()
26+ obj: Optional[ Object] = Object()
2627 r = ref(obj, lambda x: _callback_called_cache.__setitem__("ref", True))
2728 assert r() is obj
2829 obj = None
2930 assert r() is None, r()
3031 assert _callback_called_cache["ref"] is True
3132
3233def test_weakref_proxy() -> None:
33- obj: Object | None = Object()
34+ obj: Optional[ Object] = Object()
3435 p = proxy(obj)
3536 assert obj.some_meth() == 1
3637 assert p.some_meth() == 1
@@ -40,7 +41,7 @@ def test_weakref_proxy() -> None:
4041 p.some_meth()
4142
4243def test_weakref_proxy_with_callback() -> None:
43- obj: Object | None = Object()
44+ obj: Optional[ Object] = Object()
4445 p = proxy(obj, lambda x: _callback_called_cache.__setitem__("proxy", True))
4546 assert obj.some_meth() == 1
4647 assert p.some_meth() == 1
0 commit comments