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 sports.py to use NamedTuple, fix mypy errors #201

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

tianyizheng02
Copy link
Contributor

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

Run mypy with --strict flag to fix type hints in sports.py

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.

Before:

mypy --strict pittapi/sports.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/sports.py:36: error: Returning Any from function declared to return "str"  [no-any-return]
pittapi/sports.py:39: error: Missing type parameters for generic type "dict"  [type-arg]
pittapi/sports.py:82: error: Returning Any from function declared to return "str"  [no-any-return]
pittapi/sports.py:95: error: Returning Any from function declared to return "str"  [no-any-return]
pittapi/sports.py:98: error: Missing type parameters for generic type "dict"  [type-arg]
pittapi/sports.py:140: error: Returning Any from function declared to return "str"  [no-any-return]
pittapi/sports.py:143: error: Missing type parameters for generic type "dict"  [type-arg]
pittapi/sports.py:144: error: Returning Any from function declared to return "dict[Any, Any]"  [no-any-return]
pittapi/sports.py:147: error: Missing type parameters for generic type "dict"  [type-arg]
pittapi/sports.py:148: error: Returning Any from function declared to return "dict[Any, Any]"  [no-any-return]
Found 11 errors in 2 files (checked 1 source file)

After:

> mypy --strict pittapi/sports.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.
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.

1 participant