MyPy ask for a type annotation in an example, but everything is already typed in the classmethod called...
We use the correct way to type classmethod in SigningKey
class, regarding that you can not annotate a class type inside his declaration.
See : https://mypy.readthedocs.io/en/stable/generics.html#generic-methods-and-generic-self
But mypy
is complaining on an example :
examples/save_and_load_private_key_file_wif.py:52: error: Need type annotation for 'loaded_signer'
examples/save_and_load_private_key_file_wif.py:54: error: Cannot determine type of 'loaded_signer'
Using the debug command reveal_type()
of mypy
give us the type returned by the classmethod :
try:
# load private keys from file
reveal_type(SigningKey.from_wif_file(PRIVATE_KEY_FILE_PATH))
loaded_signer = SigningKey.from_wif_file(PRIVATE_KEY_FILE_PATH)
examples/save_and_load_private_key_file_wif.py:50: error: Revealed type is '<nothing>'
-
Workaround solution for Python 3.5 and 3.6: add required type annotation everytime we call a classmethod.
-
To test : upgrading to Python 3.7 will allow us to use the postponed annotations feature, that, may be, could resolve the problem:
https://stackoverflow.com/questions/44640479/mypy-annotation-for-classmethod-returning-instance