Skip to content
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

Merged
merged 7 commits into from
May 23, 2024
Merged

Conversation

beauxq
Copy link
Collaborator

@beauxq beauxq commented Mar 31, 2024

What is this fixing or adding?

get_fuzzy_results

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)

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 be None if someone is not in windows, and macos doesn't have their open, and linux doesn't have any of those other opens.

Line 606, mypy and pyright can see that that's int without the annotation. (And with the int they don't like the redeclaration, because it's declared as a parameter.)

How was this tested?

Just type checking and unit tests.

`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`)
@github-actions github-actions bot added affects: core Issues/PRs that touch core and may need additional validation. waiting-on: peer-review Issue/PR has not been reviewed by enough people yet. labels Mar 31, 2024
@Exempt-Medic Exempt-Medic added the is: refactor/cleanup Improvements to code/output readability or organizization. label Apr 8, 2024
Copy link
Member

@black-sliver black-sliver left a 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).

Utils.py Outdated Show resolved Hide resolved
@black-sliver
Copy link
Member

Sorry :-(

Copy link
Member

@black-sliver black-sliver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@black-sliver black-sliver merged commit d09b214 into ArchipelagoMW:main May 23, 2024
16 checks passed
jnschurig pushed a commit to Tranquilite0/Archipelago-SoulBlazer that referenced this pull request Jun 13, 2024
* 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]>
sflavelle pushed a commit to sflavelle/Archipelago-tgc that referenced this pull request Jun 20, 2024
* 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]>
qwint pushed a commit to qwint/Archipelago that referenced this pull request Jun 24, 2024
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects: core Issues/PRs that touch core and may need additional validation. is: refactor/cleanup Improvements to code/output readability or organizization. waiting-on: peer-review Issue/PR has not been reviewed by enough people yet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants