Message416232
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):
% cat attrslots.py
import attr
import functools
class Base:
@classmethod
def f(cls):
return 3
@attr.s(slots=True)
class Child(Base):
x: int
@classmethod
@functools.cache
def f(cls):
return super().f() + 1
print(Child.f())
% python attrslots.py
Traceback (most recent call last):
File "/Users/jelle/py/pyanalyze/samples/attrslots.py", line 21, in <module>
print(Child.f())
File "/Users/jelle/py/pyanalyze/samples/attrslots.py", line 18, in f
return super().f() + 1
TypeError: super(type, obj): obj must be an instance or subtype of type
If we provide a `types.copy_class()`, it should handle this case correctly. |
|
Date |
User |
Action |
Args |
2022-03-28 23:41:10 | JelleZijlstra | set | recipients:
+ JelleZijlstra, rhettinger, pitrou, vstinner, eric.smith, petr.viktorin, serhiy.storchaka, corona10 |
2022-03-28 23:41:10 | JelleZijlstra | set | messageid: <1648510870.03.0.271836348996.issue47143@roundup.psfhosted.org> |
2022-03-28 23:41:10 | JelleZijlstra | link | issue47143 messages |
2022-03-28 23:41:09 | JelleZijlstra | create | |
|