Skip to content

Commit

Permalink
Merge pull request #20357 from BvB93/copy2
Browse files Browse the repository at this point in the history
MAINT: Do not forward `__(deep)copy__` calls of `_GenericAlias` to the wrapped type
  • Loading branch information
charris committed Nov 12, 2021
2 parents 27a33cc + 5082397 commit 382b4cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions numpy/typing/_generic_alias.py
Expand Up @@ -178,6 +178,8 @@ def __eq__(self, value: object) -> bool:
"__mro_entries__",
"__reduce__",
"__reduce_ex__",
"__copy__",
"__deepcopy__",
})

def __getattribute__(self, name: str) -> Any:
Expand Down
16 changes: 16 additions & 0 deletions 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
Expand Down Expand Up @@ -74,6 +75,21 @@ def test_pass(self, name: str, func: FuncType) -> None:
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)()
Expand Down

0 comments on commit 382b4cb

Please sign in to comment.