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
🐛 Methods converted to staticmethods using a decorator not treated as staticmethods #13434
I've noticed this too, for both staticmethod and classmethod. Which is a shame, because application order of decorators can cause some funky stuff to happen, including but not limited to straight up errors at runtime, or typehints breaking down to *args: Any, **kwargs: Any.
If you do add arguments to the functions, the error changes to a warning that there is no self or cls argument.
Tangentially related, both of those decorators return object instances of their specific classes that are seen as e.g. staticmethod[int], but trying to hint a function or method as returning such a function causes a runtime error due to the classes not being subscriptable.
I think a possible solution would be typing entries for StaticMethod[] (and perhaps for typing_extensions too?) and ClassMethod[].
As a positive side effect, this might also stop IDE autocomplete from adding cls as a positional argument in its autocomplete, since the handling of these annotations would be different
Activity
RivenSkaye commentedon Nov 18, 2022
I've noticed this too, for both
staticmethodandclassmethod. Which is a shame, because application order of decorators can cause some funky stuff to happen, including but not limited to straight up errors at runtime, or typehints breaking down to*args: Any, **kwargs: Any.If you do add arguments to the functions, the error changes to a warning that there is no
selforclsargument.Tangentially related, both of those decorators return object instances of their specific classes that are seen as e.g.
staticmethod[int], but trying to hint a function or method as returning such a function causes a runtime error due to the classes not being subscriptable.I think a possible solution would be
typingentries forStaticMethod[](and perhaps fortyping_extensionstoo?) andClassMethod[].As a positive side effect, this might also stop IDE autocomplete from adding
clsas a positional argument in its autocomplete, since the handling of these annotations would be differentMove self argument checks to a later phase - after decorator applicat…