-
Notifications
You must be signed in to change notification settings - Fork 657
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
Core: Utils.py typing #3064
Core: Utils.py typing #3064
Conversation
`get_fuzzy_results` typing There are places that this is called with a `word_list` that is not a `Sequence`, and it is valid (e.g., `set` or `dict`). To decide the right type, we look at how `word_list` is used: - the parameter to `len` - requires `__len__` - the 2nd parameter to `map` - requires `__iter__` Then we look at https://docs.python.org/3/library/collections.abc.html#collections-abstract-base-classes and ask what is the simplest type that includes both `__len__` and `__iter__`: `Collection` (Python 3.8 requires using the alias in `typing`, instead of `collections.abc`)
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.
The
Found 40 errors in 1 file (checked 1 source file)
->
Found 33 errors in 1 file (checked 1 source file)
looks good.
I have not double-checked the changes in Collection types, but I trust they are correct.
The only "real" change (as in not just typing) I can see is the assert
in open_file
, which isn't a great message, but also it isn't worse than getting TypeError: expected str, bytes or os.PathLike object, not NoneType
from subprocess. Still suggesting a better message (for people that run from source on not-yet-supported systems).
… anyway... Co-authored-by: black-sliver <[email protected]>
Sorry :-( |
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!
* Core: Utils.py typing `get_fuzzy_results` typing There are places that this is called with a `word_list` that is not a `Sequence`, and it is valid (e.g., `set` or `dict`). To decide the right type, we look at how `word_list` is used: - the parameter to `len` - requires `__len__` - the 2nd parameter to `map` - requires `__iter__` Then we look at https://docs.python.org/3/library/collections.abc.html#collections-abstract-base-classes and ask what is the simplest type that includes both `__len__` and `__iter__`: `Collection` (Python 3.8 requires using the alias in `typing`, instead of `collections.abc`) * a bit more typing and cleaning * fine, take away my fun for something that no one is ever going to see anyway... Co-authored-by: black-sliver <[email protected]> --------- Co-authored-by: black-sliver <[email protected]>
* Core: Utils.py typing `get_fuzzy_results` typing There are places that this is called with a `word_list` that is not a `Sequence`, and it is valid (e.g., `set` or `dict`). To decide the right type, we look at how `word_list` is used: - the parameter to `len` - requires `__len__` - the 2nd parameter to `map` - requires `__iter__` Then we look at https://docs.python.org/3/library/collections.abc.html#collections-abstract-base-classes and ask what is the simplest type that includes both `__len__` and `__iter__`: `Collection` (Python 3.8 requires using the alias in `typing`, instead of `collections.abc`) * a bit more typing and cleaning * fine, take away my fun for something that no one is ever going to see anyway... Co-authored-by: black-sliver <[email protected]> --------- Co-authored-by: black-sliver <[email protected]>
* Core: Utils.py typing `get_fuzzy_results` typing There are places that this is called with a `word_list` that is not a `Sequence`, and it is valid (e.g., `set` or `dict`). To decide the right type, we look at how `word_list` is used: - the parameter to `len` - requires `__len__` - the 2nd parameter to `map` - requires `__iter__` Then we look at https://docs.python.org/3/library/collections.abc.html#collections-abstract-base-classes and ask what is the simplest type that includes both `__len__` and `__iter__`: `Collection` (Python 3.8 requires using the alias in `typing`, instead of `collections.abc`) * a bit more typing and cleaning * fine, take away my fun for something that no one is ever going to see anyway... Co-authored-by: black-sliver <[email protected]> --------- Co-authored-by: black-sliver <[email protected]>
What is this fixing or adding?
get_fuzzy_results
There are places that this is called with a
word_list
that is not aSequence
, and it is valid (e.g.,set
ordict
).To decide the right type, we look at how
word_list
is used:len
- requires__len__
map
- requires__iter__
Then we look at https://docs.python.org/3/library/collections.abc.html#collections-abstract-base-classes and ask what is the simplest type that includes both
__len__
and__iter__
:Collection
(Python 3.8 requires using the alias in
typing
, instead ofcollections.abc
)others
a few similar collection types in other places
I don't see any errors in mypy or pyright from removing the
cast
in line 104.Line 211, type checking that outside of windows reports an error.
Line 215,
open_command
would beNone
if someone is not in windows, and macos doesn't have theiropen
, and linux doesn't have any of those otheropen
s.Line 606, mypy and pyright can see that that's
int
without the annotation. (And with theint
they don't like the redeclaration, because it's declared as a parameter.)How was this tested?
Just type checking and unit tests.