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

Enforce mypy checks #87

Closed
jameslamb opened this issue May 13, 2024 · 2 comments · Fixed by #97
Closed

Enforce mypy checks #87

jameslamb opened this issue May 13, 2024 · 2 comments · Fixed by #97
Assignees
Labels

Comments

@jameslamb
Copy link
Member

Description

The Python code in this project should be checked with mypy. It isn't currently checked by any static type-checker.

Benefits of this work

  • validates the type hints, improving their usefulness as documentation
  • increases release confidence via improving the chance of some types of bugs being caught during development
  • reduces the effort required to review PRs

Acceptance Criteria

  • mypy is configured to run over this project's Python code via pre-commit

Approach

Keep as much configuration as possible in pyproject.toml, the rest in pre-commit's config. e.g.

https://github.com/rapidsai/cudf/blob/149253b2e9f3801fdcc88c17e31a25788fe6381a/pyproject.toml#L3

https://github.com/rapidsai/cudf/blob/149253b2e9f3801fdcc88c17e31a25788fe6381a/.pre-commit-config.yaml#L32

Notes

As of this writing, the latest version of mypy (v1.10)`, run like this in a Python 3.10 environment ...

mypy \
    --ignore-missing-imports \
    --explicit-package-bases \
    ./src

... yields the following

Found 26 errors in 2 files (checked 7 source files) (click me)
src/rapids_dependency_file_generator/_config.py:7: error: Library stubs not installed for "yaml"  [import-untyped]
src/rapids_dependency_file_generator/_config.py:7: note: Hint: "python3 -m pip install types-PyYAML"
src/rapids_dependency_file_generator/_config.py:7: note: (or run "mypy --install-types" to install all missing stub packages)
src/rapids_dependency_file_generator/_config.py:7: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
src/rapids_dependency_file_generator/_config.py:171: error: Argument 1 to "_parse_outputs" has incompatible type "object"; expected "str | list[str]"  [arg-type]
src/rapids_dependency_file_generator/_config.py:173: error: No overload variant of "list" matches argument type "object"  [call-overload]
src/rapids_dependency_file_generator/_config.py:173: note: Possible overload variants:
src/rapids_dependency_file_generator/_config.py:173: note:     def [_T] __init__(self) -> list[_T]
src/rapids_dependency_file_generator/_config.py:173: note:     def [_T] __init__(self, Iterable[_T], /) -> list[_T]
src/rapids_dependency_file_generator/_config.py:174: error: "object" has no attribute "items"  [attr-defined]
src/rapids_dependency_file_generator/_config.py:175: error: Argument 1 to "Path" has incompatible type "object"; expected "str | PathLike[str]"  [arg-type]
src/rapids_dependency_file_generator/_config.py:176: error: Argument 1 to "Path" has incompatible type "object"; expected "str | PathLike[str]"  [arg-type]
src/rapids_dependency_file_generator/_config.py:177: error: Argument 1 to "Path" has incompatible type "object"; expected "str | PathLike[str]"  [arg-type]
src/rapids_dependency_file_generator/_config.py:185: error: Argument "pip" to "PipRequirements" has incompatible type "str"; expected "list[str]"  [arg-type]
src/rapids_dependency_file_generator/_config.py:195: error: "object" has no attribute "__iter__"; maybe "__dir__" or "__str__"? (not iterable)  [attr-defined]
src/rapids_dependency_file_generator/_config.py:208: error: "object" has no attribute "__iter__"; maybe "__dir__" or "__str__"? (not iterable)  [attr-defined]
src/rapids_dependency_file_generator/_config.py:244: error: "object" has no attribute "items"  [attr-defined]
src/rapids_dependency_file_generator/_config.py:246: error: "object" has no attribute "items"  [attr-defined]
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:10: error: Library stubs not installed for "yaml"  [import-untyped]
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:33: error: Value of type variable "AnyStr" of "walk" cannot be "PathLike[Any] | Any"  [type-var]
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:34: error: Need type annotation for "fn"  [var-annotated]
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:34: error: Argument 1 to "filter" has incompatible type "Callable[[Any], Any]"; expected "Callable[[PathLike[Any] | Any], TypeGuard[Never]]"  [arg-type]
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:34: error: Item "PathLike[Any]" of "PathLike[Any] | Any" has no attribute "endswith"  [union-attr]
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:65: error: Argument 1 to "append" of "list" has incompatible type "dict[str, list[str]]"; expected "str"  [arg-type]
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:66: error: Incompatible return value type (got "list[str]", expected "list[str | dict[str, str]]")  [return-value]
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:66: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:66: note: Consider using "Sequence" instead, which is covariant
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:66: note: Perhaps you need a type annotation for "deduped"? Suggestion: "list[str | dict[str, str]]"
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:69: error: "Generator" expects 3 type arguments, but 1 given  [type-arg]
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:144: error: Argument 1 to "join" of "str" has incompatible type "list[str | dict[str, list[str]]]"; expected "Iterable[str]"  [arg-type]
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:183: error: Incompatible types in assignment (expression has type "Item | Container", variable has type "TOMLDocument")  [assignment]
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:188: error: "TOMLDocument" has no attribute "is_super_table"  [attr-defined]
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:191: error: Incompatible types in assignment (expression has type "Item | Container", variable has type "TOMLDocument")  [assignment]
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:425: error: Argument "dependencies" to "make_dependency_file" has incompatible type "list[str | dict[str, str]]"; expected "list[str | dict[str, list[str]]]"  [arg-type]
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:426: error: Argument "extras" to "make_dependency_file" has incompatible type "FileExtras | None"; expected "FileExtras"  [arg-type]
Found 26 errors in 2 files (checked 7 source files)

And another 25 or so if using mypy --strict.

@jameslamb
Copy link
Member Author

Once #94 is merged, there will just be a few left.

Found 4 errors in 1 file (checked 7 source files) (click me)
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:146: error: Argument 1 to "join" of "str" has incompatible type "Sequence[Union[str, dict[str, list[str]]]]"; expected "Iterable[str]"  [arg-type]
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:188: error: Incompatible types in assignment (expression has type "Union[Item, Container]", variable has type "TOMLDocument")  [assignment]
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:193: error: "TOMLDocument" has no attribute "is_super_table"  [attr-defined]
src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py:196: error: Incompatible types in assignment (expression has type "Union[Item, Container]", variable has type "TOMLDocument")  [assignment]
Found 4 errors in 1 file (checked 7 source files)

@GPUtester
Copy link

🎉 This issue has been resolved in version 1.13.11 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants