[issue47143] Add types.copy_class() which updates closures

2022-04-02 Thread STINNER Victor
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

[issue47143] Add types.copy_class() which updates closures

2022-04-02 Thread Lumír Balhar
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. --

[issue47143] Add types.copy_class() which updates closures

2022-03-28 Thread Jelle Zijlstra
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):

[issue47143] Add types.copy_class() which updates closures

2022-03-28 Thread STINNER Victor
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

[issue47143] Add types.copy_class() which updates closures

2022-03-28 Thread STINNER Victor
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."