You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Stubgen generates __mypy-replace method for @dataclass_transform #18081
Here def native_value(self) is decorated with @property or @cached_property from either functools or propcache, none of these work.
Mypy passes if I remove decorators in number.py but that changes code behaviour.
In original home assistant code base mypy accepts methods decorated with @property when superclass method is decorated with @propcache.cached_property.
Thanks for raising this issue. I'm hit with the same bug on my project and was bumping my head.
Would be nice if support for arbitrary decorators would be added, as these are part of the method signature and mypy fails when signature is not the same. Not sure what would be the reason to drop unknown decorators from the stubs generated, as that renders the whole stub useless.
Please leave discussion of unrelated problems out of this issue. Feel free to open a new issue (or look for an existing one) if you have feedback that isn't related to this __mypy-replace method.
Activity
hamdanal commentedon Nov 2, 2024
Another problem is that stubgen swallows the
@dataclass_transformdecoratorKapJI commentedon Nov 5, 2024
@hamdanal This is unrelated to this bug but do you think it's possible to make stubgen preserve arbitrary decorators?
E.g. home assistant uses
@cached_propertyfrompropcacheextensively, stubgen swallows it and then mypy emits error on code that uses generated stubs:Here
def native_value(self)is decorated with@propertyor@cached_propertyfrom eitherfunctoolsorpropcache, none of these work.Mypy passes if I remove decorators in
number.pybut that changes code behaviour.In original home assistant code base mypy accepts methods decorated with
@propertywhen superclass method is decorated with@propcache.cached_property.hamdanal commentedon Nov 9, 2024
The decision to ignore unknown decorators predates my contributions to stubgen. I suggest you open a new issue asking for this to be supported.
bramstroker commentedon Nov 9, 2024
Thanks for raising this issue. I'm hit with the same bug on my project and was bumping my head.
Would be nice if support for arbitrary decorators would be added, as these are part of the method signature and mypy fails when signature is not the same. Not sure what would be the reason to drop unknown decorators from the stubs generated, as that renders the whole stub useless.
JelleZijlstra commentedon Nov 9, 2024
Please leave discussion of unrelated problems out of this issue. Feel free to open a new issue (or look for an existing one) if you have feedback that isn't related to this
__mypy-replacemethod.stubgen: do not include mypy generated symbols (#18137)
[stubgen] Preserve dataclass_transform decorator (#18418)
hamdanal commentedon Jan 25, 2025
Fixed by #18137 and #18418