question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add type hints to eth module

See original GitHub issue

Background

Type hints allow us to perform static type checking, among other things. They raise the security bar by catching bugs at development time that, without type support, may turn into runtime bugs.

This stackoverflow answer does a great job at describing their main benefits.

What is wrong?

We currently enforce type hints for the entire p2p and trinity package. While the eth package does have some type hints already, the coverage isn’t at 100 % and while it is agreed up on that new code needs to land with type hints, there is not technical enforcement of this rule in place yet.

This needs to be fixed by:

  1. Adding all missing type hints.
  2. Enforcing (stricter) type checking in CI

How

There does exist tooling (monkeytype) to the generation of type hints for existing code bases. From my personal experience monkeytype can be helpful but does still require manual fine tuning. Also, manually adding these type hints does serve as a great boost to the general understanding of the code base as it forces one to think about the code.

  1. Run mypy --follow-imports=silent --warn-unused-ignores --ignore-missing-imports --no-strict-optional --check-untyped-defs --disallow-incomplete-defs --disallow-untyped-defs --disallow-any-generics -p eth

  2. Eliminate every reported error by adding the right type hint

  3. This should probably be done incrementally in roughly the following steps.

  • eth.tools (eligible for payout of 150 DAI)
  • eth.vm (eligible for payout of 350 DAI)
  • everything that is not eth.vm (eligible for payout of 300 DAI)

The reason for this order is, that it makes it easy to incrementally update the tox.ini to enforce stricter rules for such each package without cluttering tox.ini too much.

  1. Send frequent pull requests for chunks of work

Definition of done

This issue is done when the following criteria are met:

  1. The following configuration in tox.ini is changed.

https://github.com/ethereum/py-evm/blob/8f74e6b920e1fd4d810724ea842e8a8344ea7094/tox.ini#L107

It needs to be:

mypy --follow-imports=silent --warn-unused-ignores --ignore-missing-imports --no-strict-optional --check-untyped-defs --disallow-incomplete-defs --disallow-untyped-defs --disallow-any-generics -p eth
  1. Usage of type: ignore (silencing the type checker) is minimized and there’s a reasonable explanation for its usage

Stretch goals

When this issue is done, stretch goals can be applied (and individually get funded) to tighten type support to qualify:

  1. mypy --strict --follow-imports=silent --ignore-missing-imports --no-strict-optional -p eth -p p2p -p trinity

  2. mypy --strict --follow-imports=silent --ignore-missing-imports -p eth -p p2p -p trinity

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:38 (30 by maintainers)

github_iconTop GitHub Comments

1reaction
spm32commented, Nov 14, 2018

Sorry for waiting until the end to pay you @Bhargavasomu, thanks for bearing with me, we had a few small technical difficulties with the milestone based payments.

1reaction
cburgdorfcommented, Nov 8, 2018

@Bhargavasomu It’s hard for me to tell without seeing it in context with the applied type hint and then probably diving into it myself. Just put an type: ignore on it for now and I’ll take a look when I review the PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add type hints and expose them via PEP561 #1112 - GitHub
The web3.py library isn't written with type hints. This needs to be fixed by: Adding all missing type hints. Enforcing type checking in...
Read more >
Type hints for types from modules which may not be loaded?
Assuming Python >= 3.7, add a from __future__ import annotations import in order to postpone type hint evaluation.
Read more >
eth-typing Documentation
The following types are available from the eth_typing module. ... Add new BLSPrivateKey type for BLS private key (#23).
Read more >
Python Type Hints: How to Gradually Add Types for Third ...
One place you can apply graduality with Mypy is in the type hints for third party packages. The default course of action is...
Read more >
Don't be afraid of Python's type hints | by Zeth - Medium
Type hints help document to yourself and other people what you want your code to do. It takes no more work than the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found