Open tombulled opened 2 years ago
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
Bug Report The
@staticmethod
decorator only appears to work with MyPy when used as a decorator.For example, the following code works:
However, the following code does not work:
The above code produces the following error:
To Reproduce
Expected Behavior MyPy sees that the decorator returns a
staticmethod
and proceeds to treatMyClass.my_method
as astaticmethod
Actual Behavior MyPy produces the following error:
The above error implies that MyPy is not treating the method as a
staticmethod
.Your Environment
mypy.ini
(and other config files): N/A