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 JelleZijlstra
Recipients JelleZijlstra, corona10, eric.smith, petr.viktorin, pitrou, rhettinger, serhiy.storchaka, vstinner
Date 2022-03-28.23:41:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1648510870.03.0.271836348996.issue47143@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2022-03-28 23:41:10JelleZijlstrasetrecipients: + JelleZijlstra, rhettinger, pitrou, vstinner, eric.smith, petr.viktorin, serhiy.storchaka, corona10
2022-03-28 23:41:10JelleZijlstrasetmessageid: <1648510870.03.0.271836348996.issue47143@roundup.psfhosted.org>
2022-03-28 23:41:10JelleZijlstralinkissue47143 messages
2022-03-28 23:41:09JelleZijlstracreate