-
Notifications
You must be signed in to change notification settings - Fork 16
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
Enable type checking for users and add types to nearly everything #156
base: master
Are you sure you want to change the base?
Conversation
fixes #158 |
I got carried away and added types nearly everywhere. For CompleteSet there is an issue since its API is quite strange (though I understand the intent) For Vector this can't be done efficiently because it relies on mixing |
Final comment: any good reason why |
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.
Thanks for taking the time to do this, I've been meaning to add types for a long time.
The PR will likely need reformatting and I suggest squashing the commits as well, but thanks for separating things so it's easier to review.
@@ -64,5 +67,7 @@ def add(self, term, field, metadata): | |||
else: | |||
self.metadata[term][field][key] = metadata[key] | |||
|
|||
def __eq__(self, other): | |||
def __eq__(self, other: object): |
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.
Why is this not also MatchData
as above?
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.
This is because __eq__
by definition has to accept any object as an argument, even if a comparison with that object is not possible - mypy
will give a specific warning about this.
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 feel like this should be documented in mypy
's documentation somewhere but I can't figure out where! It's also explained here: https://stackoverflow.com/questions/54801832/mypy-eq-incompatible-with-supertype-object
Formatted, type-checked, toxed, squashed and force-pushed! |
Question - should I rebase the other PRs on top of this one? That will take some editing because of all of the types. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #156 +/- ##
==========================================
- Coverage 96.02% 95.82% -0.21%
==========================================
Files 48 48
Lines 3171 3257 +86
==========================================
+ Hits 3045 3121 +76
- Misses 126 136 +10 ☔ View full report in Codecov by Sentry. |
Some of the code (pipeline.py) had some types. But this wasn't super useful because the magical
py.typed
file was not included in the package.So this adds that, but also adds some types.
I can't totally figure out how to use
Protocol
correctly for pipeline functions but in actual fact they have a fixed signature, and the attributes we add are purely for internal use, so it'stype: ignore
for the time being.