STINNER Victor added the comment:
Lumír Balhar:
> Do you think it's a good idea to start a PR with a copy of the implementation
> from attrs for Python 3.11? We can then add tests for the new function and
> also some for dataclasses where this new function is needed and try to find
> all
Lumír Balhar added the comment:
Do you think it's a good idea to start a PR with a copy of the implementation
from attrs for Python 3.11? We can then add tests for the new function and also
some for dataclasses where this new function is needed and try to find all
corner cases.
--
Jelle Zijlstra added the comment:
I mean that the code sample above from attrs doesn't properly update the
closure for wrapped methods, such as those created by @functools.cache, or any
other arbitrary decorator that creates a wrapper function.
Example (with Python 3.9.4 and attrs 21.4.0):
STINNER Victor added the comment:
Jelle Zijlstra:
> I believe the attrs code wouldn't work if a method is decorated with a
> decorator that wraps the original function, such as @functools.cache.
What do you mean by "wouldn't work"? Do you mean that the semantics of
"copy_class()" should be
STINNER Victor added the comment:
The stdlib types module looks like a better place for such new function, rather
than the functools module.
The types module documentation starts with: "This module defines utility
functions to assist in dynamic creation of new types."