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

pip_api: type hints #97

Merged
merged 7 commits into from
Sep 14, 2021
Merged

pip_api: type hints #97

merged 7 commits into from
Sep 14, 2021

Conversation

woodruffw
Copy link
Collaborator

@woodruffw woodruffw commented Sep 13, 2021

I believe this covers the majority of the public API surface; will test these hints against my work in pip-audit.

Closes #96.

We're not doing any expensive imports, so this isn't necessary.
@woodruffw
Copy link
Collaborator Author

woodruffw commented Sep 13, 2021

Turns out that this is a significant pain due to the vendored modules:

$ mypy pip_api
pip_api/_vendor/pyparsing.py:123: error: Module "itertools" has no attribute "ifilterfalse"; maybe "filterfalse"?
pip_api/_vendor/pyparsing.py:123: error: Name "filterfalse" already defined (possibly by an import)
pip_api/_vendor/pyparsing.py:126: error: Module "_thread" has no attribute "RLock"
pip_api/_vendor/pyparsing.py:143: error: Cannot find implementation or library stub for module named "ordereddict"
pip_api/_vendor/pyparsing.py:143: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
pip_api/_vendor/pyparsing.py:143: error: Name "_OrderedDict" already defined (possibly by an import)
pip_api/_vendor/pyparsing.py:145: error: Cannot assign to a type
pip_api/_vendor/pyparsing.py:145: error: Incompatible types in assignment (expression has type "None", variable has type "Type[OrderedDict[Any, Any]]")
pip_api/_vendor/pyparsing.py:150: error: Name "SimpleNamespace" already defined (possibly by an import)
pip_api/_vendor/pyparsing.py:233: error: Module has no attribute "maxint"
pip_api/_vendor/pyparsing.py:234: error: Name "xrange" is not defined
pip_api/_vendor/pyparsing.py:236: error: Name "_ustr" already defined on line 227
pip_api/_vendor/pyparsing.py:260: error: Cannot find implementation or library stub for module named "__builtin__"
pip_api/_vendor/pyparsing.py:1800: error: Name "_FifoCache" already defined on line 1771
pip_api/_vendor/pyparsing.py:1829: error: Need type annotation for "packrat_cache" (hint: "packrat_cache: Dict[<type>, <type>] = ...")
pip_api/_vendor/pyparsing.py:2902: error: "Type[ParserElement]" has no attribute "_literalStringClass"
pip_api/_vendor/pyparsing.py:5086: error: Not all arguments converted during string formatting
pip_api/_vendor/pyparsing.py:5944: error: "Callable[[VarArg(Any), KwArg(Any)], Any]" has no attribute "ANY_VALUE"
pip_api/_vendor/pyparsing.py:6730: error: Need type annotation for "_ranges" (hint: "_ranges: List[<type>] = ...")
pip_api/_vendor/pyparsing.py:6799: error: Need type annotation for "_ranges" (hint: "_ranges: List[<type>] = ...")
Found 19 errors in 1 file (checked 21 source files)

The CI will pass above, but the parent call to mypy in pip-audit will continue to fail because of these inner errors. I've tried to mark the imports for pyparsing with # type: ignore, but that doesn't seem to have done anything...

Edit: I've added mypy to the CI to (hopefully) demonstrate the failure.

@woodruffw
Copy link
Collaborator Author

Urgh, this might actually be fixable with py.typed. Will dig in further tomorrow.

@woodruffw
Copy link
Collaborator Author

Okay: in local testing, adding py.typed to the distribution allows pip-audit to typecheck against its usage of pip-api, since said usage is limited to the public APIs that we've annotated.

For the package itself, mypy in the CI still won't work, for the vendoring reasons mentioned above. If that's acceptable, this should be good to go 🙂

setup.py Outdated Show resolved Hide resolved
@di
Copy link
Owner

di commented Sep 13, 2021

For the package itself, mypy in the CI still won't work, for the vendoring reasons mentioned above. If that's acceptable, this should be good to go 🙂

I think that's acceptable for now.

@woodruffw woodruffw marked this pull request as ready for review September 14, 2021 15:03
@woodruffw
Copy link
Collaborator Author

Okay, this should be good to go once the CI goes through!

A minor bump once it's merged would also be appreciated 🙂

@di di merged commit 8a25eb3 into di:master Sep 14, 2021
@woodruffw woodruffw deleted the ww/types branch September 14, 2021 15:38
@di
Copy link
Owner

di commented Sep 14, 2021

Released in https://pypi.org/project/pip-api/0.0.21/

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.

Type hints?
2 participants