-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add mypy type checking #269
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i find these changes very helpful and well done.
distro.py
Outdated
@@ -37,6 +37,40 @@ | |||
import argparse | |||
import subprocess | |||
|
|||
if False: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the rationale for this condition? is that to work with Python 2, where no typing.TYPE_CHECKING
is available? if so, a short comment would help in the long term for other readers.
amending # pragma: nocover
to this line should calm down that automated commenter here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @funkyfuture. I have applied your suggestions to the latest revision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks good, just need to hook it up to GHA (and one more comment too)
Type checking helps build confidence that an internally consistent API is used correctly. Use type comments rather than annotations to retain compatibility with Python 2.7. The functools.cached_property is now used on Python 3.8+ as this helps mypy understand the type of the cached property. Rationale --------- The pip project vendors a copy of distro.py: https://github.com/pypa/pip/blob/20.3.3/src/pip/_vendor/distro.py pip also uses mypy. Right, pip must workaround or ignore type errors that occur from calls to distro.py. By including types directly in the library, it will help distro, pip, and any other library users running mypy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
Type checking helps build confidence that an internally consistent API
is used correctly.
Use type comments rather than annotations to retain compatibility with
Python 2.7.
The functools.cached_property is now used on Python 3.8+ as this helps
mypy understand the type of the cached property.
Rationale
The pip project vendors a copy of distro.py:
https://github.com/pypa/pip/blob/20.3.3/src/pip/_vendor/distro.py
pip also uses mypy. Right now, pip must workaround or ignore type errors
that occur from calls to distro.py. By including types directly in the
library, it will help distro, pip, and any other library users running
mypy.