This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author JacobHayes
Recipients JacobHayes
Date 2021-09-10.17:09:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1631293792.65.0.39078575611.issue45167@roundup.psfhosted.org>
In-reply-to
Content
When deepcopying a parametrized types.GenericAlias (eg: a dict subclass) that has a __deepcopy__ method, the copy module doesn't detect the GenericAlias as a type and instead tries to call cls.__deepcopy__, passing `memo` inplace of self. This doesn't seem to happen with `typing.Generic` however.

Example:
```
from copy import deepcopy


class X(dict):
    def __deepcopy__(self, memo):
        return self


print(deepcopy(X()))
print(deepcopy(X))

print(type(X[str, int]))
print(deepcopy(X[str, int]()))
print(deepcopy(X[str, int]))
```
shows
```
{}
<class '__main__.X'>
<class 'types.GenericAlias'>
{}
Traceback (most recent call last):
  File "/tmp/demo.py", line 14, in <module>
    print(deepcopy(X[str, int]))
  File "/Users/jacobhayes/.pyenv/versions/3.9.6/lib/python3.9/copy.py", line 153, in deepcopy
    y = copier(memo)
TypeError: __deepcopy__() missing 1 required positional argument: 'memo'
```

I don't know if it's better to update `copy.deepcopy` here or perhaps narrow the `__getattr__` for `types.GenericAlias` (as `typing. _BaseGenericAlias` seems to).
History
Date User Action Args
2021-09-10 17:09:52JacobHayessetrecipients: + JacobHayes
2021-09-10 17:09:52JacobHayessetmessageid: <1631293792.65.0.39078575611.issue45167@roundup.psfhosted.org>
2021-09-10 17:09:52JacobHayeslinkissue45167 messages
2021-09-10 17:09:52JacobHayescreate