-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add type hints and expose via PEP561 #69
Comments
I like to start working on this issue, please consider my application. @pipermerriam |
* Fixes first part of ethereum#69 TODO: Add all missing type hints
@6ug go for it. |
@pipermerriam I would like to work on this, as there has been no progress till now. One doubt that I had was, is the type of
Here we have |
No, I believe that node can be any of the following (you should confirm as it's been a while since I was in this codebase)
Probably good to define these once and re-use them across the codebase. Also, you've got the 👍 from me to work on this. |
@pipermerriam @cburgdorf I started type hinting the codebase, but it turned out ugly and I feel that we could refactor the code with the usage of more classes like I would like to refactor the code first as part of another issue, and till then maybe this issue can be blocked. I would need help from you during the refactoring phase. Am I good to go for refactoring? |
And one more doubt I had is the following
Any updates or instructions based on the above code? Like should there be only |
@Bhargavasomu see this guide for a "better" way to link to existing code: https://help.github.com/articles/creating-a-permanent-link-to-a-code-snippet/ |
The warning code you linked above is us maintaining backwards compatibility back a few months ago when it looked like we'd have a separate binary trie implementation in the codebase. We can probably remove that support, though it will require us to do a major version bump (something you don't have to worry about). However, I don't see us needing to remove it other than for cleanup reasons so I'd suggest not getting sidetracked with that unless you have a specific reason for doing it. |
@Bhargavasomu I think it could be an improvement to have the different node types have concrete classes. The devil is going to be in the details/implementation. I'd suggest looking into use of named tuples for this. In general, I support this concept and in general, cleanup of this codebase which hasn't been touched much in the last 1.5 years. I'm hesitant to commit a bounty to this at this stage since it isn't clear yet whether the effort will produce the desired improvement. But, If this does work out well, I will work to get you compensated in some way (as I know you're a bit of a bounty hunter) and I like seeing people paid for good work. |
@Bhargavasomu if you choose to undertake this task, can you open a new issue that provides a high level outline for your plan and we can track progress there. |
@pipermerriam will come up with a good detailed implementation detail and open an issue in a couple of days. |
@pipermerriam is there any documentation available apart from |
Not really. 😢 This codebase was written by 1) referencing the yellow paper which is very cryptic and not easy to read and 2) using the implementation that was already done in the |
@pipermerriam will go through the |
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?
This library currently does not have any type hints.
This needs to be fixed by:
eth-typing>=2.0.0,<3
library as a dependency.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.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 trie
Eliminate every reported error by adding the right type hint
Because this library supports older versions of python, the type hints will not be able to use the modern python3.6 syntax.
Definition of done
This issue is done when the following criteria are met:
mypy
is run in CIAdd a new command to the
flake8
environment in thetox.ini
file that runs:type: ignore
(silencing the type checker) is minimized and there's a reasonable explanation for its usagesetup.py
to expose this data to other libraries as was done here: Enable discovery of type hints as per PEP561 eth-typing#10Stretch goals
When this issue is done, stretch goals can be applied (and individually get funded) to tighten type support to qualify:
mypy --strict --follow-imports=silent --ignore-missing-imports --no-strict-optional -p trie
The text was updated successfully, but these errors were encountered: