summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2021-11-12 09:53:57 -0700
committerGitHub <noreply@github.com>2021-11-12 09:53:57 -0700
commit382b4cb9821e887e3393cd48c7fa09f83bf73211 (patch)
tree9e404e0a0f546d24b989de3a8f7f7059e4c4f279
parent27a33ccc59a5d84c7683120552c41c237c919322 (diff)
parent50823973e857363f7d8052768276c2e86f004d61 (diff)
downloadnumpy-382b4cb9821e887e3393cd48c7fa09f83bf73211.tar.gz
Merge pull request #20357 from BvB93/copy2
MAINT: Do not forward `__(deep)copy__` calls of `_GenericAlias` to the wrapped type
-rw-r--r--numpy/typing/_generic_alias.py2
-rw-r--r--numpy/typing/tests/test_generic_alias.py16
2 files changed, 18 insertions, 0 deletions
diff --git a/numpy/typing/_generic_alias.py b/numpy/typing/_generic_alias.py
index 68523827a..4195cd93e 100644
--- a/numpy/typing/_generic_alias.py
+++ b/numpy/typing/_generic_alias.py
@@ -178,6 +178,8 @@ class _GenericAlias:
"__mro_entries__",
"__reduce__",
"__reduce_ex__",
+ "__copy__",
+ "__deepcopy__",
})
def __getattribute__(self, name: str) -> Any:
diff --git a/numpy/typing/tests/test_generic_alias.py b/numpy/typing/tests/test_generic_alias.py
index 5f0ac9153..35c0da349 100644
--- a/numpy/typing/tests/test_generic_alias.py
+++ b/numpy/typing/tests/test_generic_alias.py
@@ -1,6 +1,7 @@
from __future__ import annotations
import sys
+import copy
import types
import pickle
import weakref
@@ -74,6 +75,21 @@ class TestGenericAlias:
value_ref = func(NDArray_ref)
assert value == value_ref
+ @pytest.mark.parametrize("name,func", [
+ ("__copy__", lambda n: n == copy.copy(n)),
+ ("__deepcopy__", lambda n: n == copy.deepcopy(n)),
+ ])
+ def test_copy(self, name: str, func: FuncType) -> None:
+ value = func(NDArray)
+
+ # xref bpo-45167
+ GE_398 = (
+ sys.version_info[:2] == (3, 9) and sys.version_info >= (3, 9, 8)
+ )
+ if GE_398 or sys.version_info >= (3, 10, 1):
+ value_ref = func(NDArray_ref)
+ assert value == value_ref
+
def test_weakref(self) -> None:
"""Test ``__weakref__``."""
value = weakref.ref(NDArray)()