Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • DuniterPy DuniterPy
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 39
    • Issues 39
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 2
    • Merge requests 2
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • clients
  • python
  • DuniterPyDuniterPy
  • Issues
  • #93
Closed
Open
Created Jun 09, 2019 by Vincent Texier@vtexierOwner

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

Edited Mar 07, 2021 by Moul
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking