diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py index f1ca8cb254d1887..344a964e732adbb 100644 --- a/Lib/test/test_copy.py +++ b/Lib/test/test_copy.py @@ -874,6 +874,12 @@ def m(self): self.assertIs(g.b.__self__, g) g.b() + def test_deepcopy_generic_alias(self): + x = list[int] + g = copy.deepcopy(x) + + self.assertEqual(x, g) + def global_foo(x, y): return x+y diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-09-13-11-15-33.bpo-45167.lupMrM.rst b/Misc/NEWS.d/next/Core and Builtins/2021-09-13-11-15-33.bpo-45167.lupMrM.rst new file mode 100644 index 000000000000000..6aff3a34630dd53 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2021-09-13-11-15-33.bpo-45167.lupMrM.rst @@ -0,0 +1,2 @@ +Add ability to deepcopy ``types.GenericAlias``. Patch provided by Yurii +Karabas. diff --git a/Objects/genericaliasobject.c b/Objects/genericaliasobject.c index 38b68e410c443c3..dbe5d89b7396296 100644 --- a/Objects/genericaliasobject.c +++ b/Objects/genericaliasobject.c @@ -418,6 +418,8 @@ static const char* const attr_exceptions[] = { "__mro_entries__", "__reduce_ex__", // needed so we don't look up object.__reduce_ex__ "__reduce__", + "__copy__", + "__deepcopy__", NULL, };