-
Notifications
You must be signed in to change notification settings - Fork 685
Eth leftover type hinting #1456
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
Eth leftover type hinting #1456
Conversation
@cburgdorf I have tried my level best to tighten the types. I have used
Apart from that in some places I was forced to use Will make the improvements as per the review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking pretty good! My comments are mostly smaller things and then I'll give that another round of review where I try to wrestle with some cast
/ ignore
/ Any
cases to see if we can tighten things further. These are hard for me to tell by just skimming over the PR.
@@ -99,15 +110,15 @@ def from_genesis_header(cls, | |||
""" | |||
Initializes the chain from the genesis header. | |||
""" | |||
headerdb = cls.get_headerdb_class()(base_db) | |||
headerdb = cls.get_headerdb_class()(cast(BaseAtomicDB, base_db)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
@@ -121,7 +121,7 @@ def commit_changeset(self, changeset_id: uuid.UUID) -> Dict[bytes, bytes]: | |||
# | |||
# Database API | |||
# | |||
def __getitem__(self, key: bytes) -> Union[bytes, DeletedEntry]: | |||
def __getitem__(self, key: bytes) -> Union[bytes, DeletedEntry]: # type: ignore # Breaks LSP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll double check this and other cases of # type: ignore
in another round of review when I get my hands on the code. Just reviewing through github now.
270452d
to
2c2b568
Compare
@cburgdorf made the changes requested. Please take a look. |
eth/db/diff.py
Outdated
else: | ||
return result | ||
return cast(bytes, result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pipermerriam @carver I'm worried about the usage of cast
in performance sensitive code paths.
Here's @gvanrossum from 2016
I would really hope we won't need to use or encourage casts here, since it's an expensive runtime operation (at least it is until we teach CPython about it -- right now it is a user-defined function, which is incredibly slow compared to a plain assignment)
I'm not sure if anything has changed about this in the meantime but if not then I assume that even if cast
is a noop
at runtime it is still one extra function call and hence will slow things down. Therefore I'd advocate to use type: ignore
in such performance sensitive code paths. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the best solution we have is a cast, then yes, a type: ignore
seems like a fine alternative to me. (given that it's in a performance-sensitive line, and the line is doing exactly one thing -- we don't want to accidentally ignore other type checks on the same line).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Bhargavasomu This looks pretty good! I pushed one more commit into this PR which uses a neat trick (StaticMethod
) that @carver came up with to get rid of some ignores. I believe we could apply the same trick to a bunch of other places that currently use type: ignore
.
However, I have one main concern which I'd like to get @pipermerriam @carver thoughts on. It's about the usage of cast()
for performance sensible code paths (those that are called very often). I believe that there's a (small) runtime cost of cast
(even though the mypy docs say there isn't). Not sure.
@cburgdorf I highly doubt that there would be considerable performance changes. Doing a |
@Bhargavasomu well, it shouldn't matter for most cases but unless CPython optimized out the See also my citation of Guido van Rossum (creator of Python)
I'm just trying to play it safe here. So my personal preference for performance critical code would be to use |
@cburgdorf could you please tell me which files are performance critical, so that I could replace |
@Bhargavasomu I'll take care of that. Applying some final finish. |
b812a12
to
1a36a01
Compare
@Bhargavasomu solid work! 👍 I wrangled with some corner cases to get rid of some I believe there are still plenty of cases where we could do better so if you like that sort of stuff feel free to continue wrangling with |
Thankyou for helping me out @cburgdorf |
hey guys, what about other bounty-marked tickets merged recently lol )) |
@rayrapetyan are you saying we missed paying out a bounty? Can you point me to it? |
@cburgdorf, e.g. #1402, thanks! |
@rayrapetyan I'm afraid that ticket did not have a Gitcoin bounty assigned. I assume that the I'm afraid we can't retroactively give out money for work that has already happened and had no bounty associated at that time. But I recognize that you've been doing great work and there's plenty of opportunity for you to do paid work on this project. How would you feel about writing a Proof of Concept GraphQL plugin as described in https://github.com/ethereum/py-evm/issues/1462. Is this something that you'd have fun with? |
@cburgdorf, no worries, I understand. I'm currently stuck with issue #62, once completed I can start with #1462. Thanks. |
What was wrong?
Completes the type hinting in the
eth
module.Closes #1398
How was it fixed?
Adding the type hints manually and adjusting in other modules like
trinity
andp2p
.Cute Animal Picture