From c87de48835823bd7a5e725cb3fe41f395331f0eb Mon Sep 17 00:00:00 2001 From: Bas van Beek Date: Mon, 12 Jul 2021 11:07:31 +0200 Subject: [PATCH] TST: Fix a `GenericAlias` test failure for python 3.9.0 --- numpy/typing/tests/test_generic_alias.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/numpy/typing/tests/test_generic_alias.py b/numpy/typing/tests/test_generic_alias.py index 8cbdd2e6e073..5f0ac915352c 100644 --- a/numpy/typing/tests/test_generic_alias.py +++ b/numpy/typing/tests/test_generic_alias.py @@ -60,7 +60,6 @@ class TestGenericAlias: ("__call__", lambda n: n(shape=(1,), dtype=np.int64, buffer=BUFFER)), ("subclassing", lambda n: _get_subclass_mro(n)), ("pickle", lambda n: n == pickle.loads(pickle.dumps(n))), - ("__weakref__", lambda n: n == weakref.ref(n)()), ]) def test_pass(self, name: str, func: FuncType) -> None: """Compare `types.GenericAlias` with its numpy-based backport. @@ -75,6 +74,14 @@ def test_pass(self, name: str, func: FuncType) -> None: value_ref = func(NDArray_ref) assert value == value_ref + def test_weakref(self) -> None: + """Test ``__weakref__``.""" + value = weakref.ref(NDArray)() + + if sys.version_info >= (3, 9, 1): # xref bpo-42332 + value_ref = weakref.ref(NDArray_ref)() + assert value == value_ref + @pytest.mark.parametrize("name", GETATTR_NAMES) def test_getattr(self, name: str) -> None: """Test that `getattr` wraps around the underlying type,