Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: Do not forward __(deep)copy__ calls of _GenericAlias to the wrapped type #20357

Merged
merged 1 commit into from Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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