-
Notifications
You must be signed in to change notification settings - Fork 685
Add type hints to eth module #1398
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
Comments
I would like to work on this. Could you please assign this to me? |
Issue Status: 1. Open 2. Started 3. Submitted 4. Done This issue now has a funding of 800.0 DAI (800.0 USD @ $1.0/DAI) attached to it.
|
1 similar comment
Issue Status: 1. Open 2. Started 3. Submitted 4. Done This issue now has a funding of 800.0 DAI (800.0 USD @ $1.0/DAI) attached to it.
|
Issue Status: 1. Open 2. Started 3. Submitted 4. Done Work has been started. These users each claimed they can complete the work by 2 months from now. 1) bhargavasomu has been approved to start work. I would make PR for type hinting of 2 modules per day and will try my level best to complete this task as soon as possible. I estimate that this issue would be solved by me within 5 days. I have a pretty good knowledge of the codebase and can solve this issue without much time waste. Maybe this request could be extended to enable type hinting of the left over models also. Please assign this to me as I feel that I can complete this fastly as I have sufficient knowledge of the codebase and mypy Learn more on the Gitcoin Issue Details page. 2) svenski123 has applied to start work (Funders only: approve worker | reject worker). I note mypy currently reports 520 type related errors and notes in the eth. I do see that there is other interest in addressing this issue, however as the issue is still currently unassigned in gitcoin I assume offers are still welcome - if this assumption is incorrect, please accept my apologies. Learn more on the Gitcoin Issue Details page. 3) bhargavasomu has applied to start work (Funders only: approve worker | reject worker). I am well versed with type hinting in python and have a good understanding of the codebase. If assigned to me, I will complete this task within at max a 3 days. Learn more on the Gitcoin Issue Details page. |
@gitcoinbot I hereby approve @Bhargavasomu working on this issue |
@Bhargavasomu You're good to go! |
@svenski123 @shalabhaggarwal the issue was given to @Bhargavasomu on a first come, first serve basis. For now it should be considered blocked (unless no sign of progress is being made within the next few days). That said, we'll probably open up more bounties for similar tasks in other related projects soon. |
@svenski123 and/or @shalabhaggarwal I don't think bounties have been added yet, but I've applied for around 10+ new bounties to be added to the |
Noting that Line 66 in e68e7c3
mypy_extensions.TypedDict
|
@cburgdorf , the Edit - Figured it out |
you can put the import behind a |
In |
I think the I think my preference would be split this into two methods:
Some name suggestions:
/cc @pipermerriam @carver |
Maybe I shouldn't be commenting at 6am but... Another option is to go as far as enumerating all the possibilities, like:
|
@carver that API looks...extreme 😅 I'd prefer just to split between single / multiple which should be enough to overcome the type ambiguity. |
I'd like to remove the support for multiple types in the stack. I think it was a bad design decision. Only type that should probably be allowed on the stack is |
👍
Just to be clear, are we talking about shorthand APIs that delegate to something like def pop3(self):
yield self.pop()
yield self.pop()
yield self.pop() Because, that just strikes me as a bit redundant compared to. def pop_num(self, num):
for _ in range(num):
yield self.pop() And then def pop3(self):
yield from self.pop_num(3) |
@cburgdorf the above method looks promising and we could still have the same function signature as the present one, just in case we need the flexibility. |
@Bhargavasomu my proposal to remove multi-type support from the stack should be done independently of this PR as it's going to touch a lot of code, but should be very straight-forward to change. |
@cburgdorf I'm inclined to do something that's really dumb and easy to read. def pop3(self):
return (self.pop(), self.pop(), self.pop()) |
The primary benefit I see is the strict return type signature. def pop(self) -> int:
...
def pop2(self) -> Tuple[int, int]:
return (self.pop(), self.pop())
def pop3(self) -> Tuple[int, int, int]:
return (self.pop(), self.pop(), self.pop()) |
Though, on second thought, this is a part of the code where raw performance matters so reducing the number of call frames would be ideal. def pop3(self):
try:
return (self.values.pop(), self.values.pop(), self.values.pop())
except IndexError:
raise InsufficientStack("...") 3 fewer call frames at the expense of requiring inline exception handling for each method... |
And deeper down the rabbit hole. def pop3(self):
popped = self.values[-3:]
if len(popped) != 3:
raise InsufficientStack("..."
del self.values[-3:]
return tuple(popped) I'm in the middle of something else but it'd be nice to profile these different approaches and see if any are clearly faster. |
@ceresstation We just merged #1420 as a first milestone to this. Can we please pay out 150 DAI (out of the entire 800 DAI) to @Bhargavasomu already? |
I guess the type hinting of the There is some part of the codebase which pushes |
^ @ceresstation, when you get the chance! |
Issue Status: 1. Open 2. Started 3. Submitted 4. Done Workers have applied to start work. These users each claimed they can complete the work by 1 month, 3 weeks ago. 1) armaspablosebastian has applied to start work (Funders only: approve worker | reject worker). There's not much mystery, I'm going to run mypy and I'm going to add all missing type hints in the required order. Learn more on the Gitcoin Issue Details page. |
@cburgdorf does #1451 complete the type hinting of the |
@cburgdorf in That said, I am using |
@cburgdorf in But looking at the code, we have used the same signature( |
I guess one of them is the |
Yes, you can. I'll make sure to trigger the payout for the Regarding |
@ceresstation Can we trigger another payout of 350 DAI to @Bhargavasomu for completing the second milestone. |
@cburgdorf I am getting the following error when I am trying to type hint the overloaded function On googling I got this, python/mypy#4619. But this doesn't give a substantial fix. Can I use |
@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 |
@ceresstation the last remaining milestone can be paid out to @Bhargavasomu |
⚡️ A tip worth 800.00000 DAI (800.0 USD @ $1.0/DAI) has been granted to @Bhargavasomu for this issue from @ceresstation. ⚡️ Nice work @Bhargavasomu! To redeem your tip, login to Gitcoin at https://gitcoin.co/explorer and select 'Claim Tip' from dropdown menu in the top right, or check your email for a link to the tip redemption page.
|
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. |
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
andtrinity
package. While theeth
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:
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 eth
Eliminate every reported error by adding the right type hint
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)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 clutteringtox.ini
too much.Definition of done
This issue is done when the following criteria are met:
tox.ini
is changed.py-evm/tox.ini
Line 107 in 8f74e6b
It needs to be:
type: ignore
(silencing the type checker) is minimized and there's a reasonable explanation for its usageStretch 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 eth -p p2p -p trinity
mypy --strict --follow-imports=silent --ignore-missing-imports -p eth -p p2p -p trinity
The text was updated successfully, but these errors were encountered: