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

Fix mypy errors and rename NamedTuple fields in gym.py #199

Merged
merged 2 commits into from
Aug 25, 2024
Merged

Conversation

tianyizheng02
Copy link
Contributor

@tianyizheng02 tianyizheng02 commented Aug 18, 2024

Contributes to #45 by fixing existing type hint errors prior to introducing mypy to the repo.

Run mypy with --strict flag and fix resulting mypy errors in gym.py.

Rename some fields in the Gym NamedTuple class in order to clarify their meanings and to fix a mypy error. The count field specifically causes a mypy error because mypy interprets the field's name as the count method that NamedTuple inherits from the base tuple class: According to the mypy devs, this is expected behavior and is not a bug:

Before:

> mypy --strict pittapi/gym.py        
pittapi/__init__.py:23: error: Skipping analyzing "gevent": module is installed, but missing library stubs or py.typed marker  [import-untyped]
pittapi/gym.py:22: error: Library stubs not installed for "bs4"  [import-untyped]
pittapi/gym.py:22: note: Hint: "python3 -m pip install types-beautifulsoup4"
pittapi/gym.py:22: note: (or run "mypy --install-types" to install all missing stub packages)
pittapi/gym.py:22: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
pittapi/gym.py:43: error: Incompatible types in assignment (expression has type "int", base class "tuple" defined the type as "Callable[[tuple[str | int, ...], Any], int]")  [assignment]
pittapi/gym.py:51: error: Argument "date" to "Gym" has incompatible type "None"; expected "str"  [arg-type]
pittapi/gym.py:51: error: Argument "count" to "Gym" has incompatible type "None"; expected "int"  [arg-type]
pittapi/gym.py:51: error: Argument "percentage" to "Gym" has incompatible type "None"; expected "int"  [arg-type]
Found 6 errors in 2 files (checked 1 source file)

After:

> mypy --strict pittapi/gym.py       
pittapi/__init__.py:23: error: Skipping analyzing "gevent": module is installed, but missing library stubs or py.typed marker  [import-untyped]
pittapi/gym.py:22: error: Library stubs not installed for "bs4"  [import-untyped]
pittapi/gym.py:22: note: Hint: "python3 -m pip install types-beautifulsoup4"
pittapi/gym.py:22: note: (or run "mypy --install-types" to install all missing stub packages)
pittapi/gym.py:22: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 2 errors in 2 files (checked 1 source file)

Like the remaining mypy errors from #193, we'll need to ignore these missing-imports errors with --ignore-missing-imports.

Add None to some type annotations in gym.py in order to fix some mypy
errors.

Rename some fields in the Gym NamedTuple class in order to clarify their
meanings and to fix a mypy error. The "count" field specifically causes
a mypy error because mypy interprets the field's name as the "count"
method that NamedTuple inherits from the base tuple class. According to
the mypy devs, this is expected behavior and is not a bug:
- python/mypy#4507
- python/mypy#17047
@tianyizheng02 tianyizheng02 merged commit 40c9a14 into dev Aug 25, 2024
4 checks passed
@tianyizheng02 tianyizheng02 deleted the mypy-gym branch August 25, 2024 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants