Skip to content

Commit e564fcb

Browse files
Merge pull request numpy#20347 from BvB93/copy
MAINT: Do not forward `__(deep)copy__` calls of `_GenericAlias` to the wrapped type
2 parents 8dbd507 + 8871c72 commit e564fcb

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

numpy/typing/_generic_alias.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ def __eq__(self, value: object) -> bool:
185185
"__mro_entries__",
186186
"__reduce__",
187187
"__reduce_ex__",
188+
"__copy__",
189+
"__deepcopy__",
188190
})
189191

190192
def __getattribute__(self, name: str) -> Any:

numpy/typing/tests/test_generic_alias.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import sys
4+
import copy
45
import types
56
import pickle
67
import weakref
@@ -80,6 +81,21 @@ def test_pass(self, name: str, func: FuncType) -> None:
8081
value_ref = func(NDArray_ref)
8182
assert value == value_ref
8283

84+
@pytest.mark.parametrize("name,func", [
85+
("__copy__", lambda n: n == copy.copy(n)),
86+
("__deepcopy__", lambda n: n == copy.deepcopy(n)),
87+
])
88+
def test_copy(self, name: str, func: FuncType) -> None:
89+
value = func(NDArray)
90+
91+
# xref bpo-45167
92+
GE_398 = (
93+
sys.version_info[:2] == (3, 9) and sys.version_info >= (3, 9, 8)
94+
)
95+
if GE_398 or sys.version_info >= (3, 10, 1):
96+
value_ref = func(NDArray_ref)
97+
assert value == value_ref
98+
8399
def test_weakref(self) -> None:
84100
"""Test ``__weakref__``."""
85101
value = weakref.ref(NDArray)()

0 commit comments

Comments
 (0)