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

Refactor library.py to use NamedTuple, fix mypy errors #202

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

tianyizheng02
Copy link
Contributor

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

Refactor library.py to store API output using NamedTuples rather than plain Python dicts. This makes the output more user-friendly, less error-prone, and easier to type-hint.

Before:

> mypy --strict pittapi/library.py
pittapi/__init__.py:23: error: Skipping analyzing "gevent": module is installed, but missing library stubs or py.typed marker  [import-untyped]
pittapi/__init__.py:23: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
pittapi/library.py:48: error: Function is missing a return type annotation  [no-untyped-def]
pittapi/library.py:48: note: Use "-> None" if function does not return a value
pittapi/library.py:86: error: Call to untyped function "HTMLStrip" in typed context  [no-untyped-call]
pittapi/library.py:145: error: Value of type "Response" is not indexable  [index]
pittapi/library.py:156: error: Value of type "Response" is not indexable  [index]
Found 5 errors in 2 files (checked 1 source file)

After:

> mypy --strict pittapi/library.py       
pittapi/__init__.py:23: error: Skipping analyzing "gevent": module is installed, but missing library stubs or py.typed marker  [import-untyped]
pittapi/__init__.py:23: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

Like in #193, the remaining missing-imports error will need to be ignored with --ignore-missing-imports because gevent simply doesn't provide any type hints for mypy.

Refactor sports.py to store API output using NamedTuples rather than
plain Python dicts. This makes the output more user-friendly, less
error-prone, and easier to type-hint.
@tianyizheng02 tianyizheng02 merged commit 54900d6 into dev Jan 14, 2025
4 checks passed
@tianyizheng02 tianyizheng02 deleted the mypy-library branch January 14, 2025 07:56
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