from typing import Callable
def super_static(func: Callable) -> staticmethod:
return staticmethod(func)
class SuperClass:
@super_static
def super_bool() -> bool:
return True
$ mypy deco.py
deco.py:8: error: Method must have at least one argument
No errors. Or at least something that I can turn off. Right now the only thing I can do is ignore_errors = true, which isn't going to work :D
$ mypy --version
mypy 0.710+dev.dadae5f6f6f99191d6a7a407660eba5e3732c397
$ python --version
Python 3.7.2
There are a handful of other @staticmethod issues (for good reason, it's complicated https://github.com/python/typeshed/issues/870 ). For my specific use case, I would like a way to get past this one
https://github.com/python/mypy/blob/b6afa7fdb7c5c87a847b5936202a81c2be30564b/mypy/semanal.py#L492
As far as I can tell, there's no valid way for me to type hint the decorator super_static because of the typeshed issue linked above. But I also couldn't figure out how to get a custom typeshed working. Is there any way for me to use this code _without_ setting ignore_errors = true? I can't # type: ignore it, no config variables allow me to bypass this, it's a full-on self.fail.
I'm asking for help on how to bypass this. Should it be: monkeypatching (vain attempt failed...hehe)? a plugin? custom typeshed is what I want? Something else?
Thanks for any thoughts. Sorry if this is indeed a duplicate of one of the others, I think on some level they are all related so if it makes sense to close this no problem. I'll still keep using mypy :slightly_smiling_face:
This is already "supported" this way:
from typing import Callable, TYPE_CHECKING
if TYPE_CHECKING:
super_static = staticmethod
else:
def super_static(func: Callable) -> staticmethod:
return staticmethod(func)
class SuperClass:
@super_static
def super_bool() -> bool: # No error
return True
This is still limited, but it is unlikely we will have something better in foreseeable future.
Excellent. Thank you very much!
Most helpful comment
This is already "supported" this way:
This is still limited, but it is unlikely we will have something better in foreseeable future.