-
Notifications
You must be signed in to change notification settings - Fork 117
Conversation
As captured in python/typeshed#1663, the types for SHA-1 and SHA-2 family of functions are callables that return a Hash instance, whilst the SHA-3 family of functions are Hash `type`s (at least in Python 3.6). Mixing the two kinds of functions together in a dictionary confuses mypy's type inference as noted in sybrenstuvel#153, so we instead add an annotation as a hint. Also, update test_my.py to match the python version set by tox.ini in CI instead of always targeting Python 3.7 (as configured in setup.cfg) to validate the types in all supported Python 3.x versions. This fix also avoids the issue with the older mypy releases for Python 3.6 / Python 3.7 found in distro repos... ... for Ubuntu: ``` docker run \ -v $(pwd):/tmp/rsa \ -w /tmp/rsa ubuntu:18.04 \ /bin/bash -c 'apt-get update -qqy \ && apt-get install -qqy python3-pyasn1 python3-setuptools python3-mypy \ && python3 setup.py test' ``` ... and for Fedora: ``` docker run \ -v $(pwd):/tmp/rsa \ -w /tmp/rsa docker.io/fedora \ /bin/bash -c 'dnf -y install wget python3-devel python3-pyasn1 python3-setuptools python3-mypy \ && python3 setup.py test' ``` Fixes sybrenstuvel#153
@sybrenstuvel : just checking in to see if there's anything I can clarify / fix with this PR to get it merged. Thanks! |
# Re-enable the standard pragma | ||
pragma: no cover |
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 does this do? What is "the standard pragma", and why does it need to be re-enabled?
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.
Note that when using the exclude_lines option in a configuration file, you are taking control of the entire list of regexes, so you need to re-specify the default “pragma: no cover” match if you still want it to apply.
from https://coverage.readthedocs.io/en/coverage-5.0/excluding.html#excluding
It makes sense you aren't currently using it anywhere since this line was missing, but for someone trying to ignore coverage, this is usually the first thing one might reach for, and can be confusing to the developer why # pragma: no cover
ends up not working if we don't add it back
@@ -34,6 +34,11 @@ | |||
|
|||
from . import common, transform, core, key | |||
|
|||
if typing.TYPE_CHECKING: | |||
HashType = hashlib._Hash |
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.
Why is this only valid while type-checking?
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.
This type is defined in a .pyi
file: https://github.com/python/mypy/blob/15bd486a67a3214fdb854ba2f1d6d524113da6c1/mypy/typeshed/stdlib/hashlib.pyi#L5 so it can't be imported at runtime.
Thanks for the PR, appreciate it. I just added a few inline questions. |
@sybrenstuvel : gentle nudge 🙂 |
Gentleness appreciated :) |
As captured in python/typeshed#1663, the types for
SHA-1 and SHA-2 family of functions are callables that return a Hash instance,
whilst the SHA-3 family of functions are Hash
type
s (at least in Python 3.6).Mixing the two kinds of functions together in a dictionary confuses mypy's type
inference as noted in #153, so we instead add an annotation as a hint.
Also, update test_my.py to match the python version set by tox.ini in CI
instead of always targeting Python 3.7 (as configured in setup.cfg) to
validate the types in all supported Python 3.x versions.
This fix also avoids the issue with the older mypy releases for
Python 3.6 / Python 3.7 found in distro repos...
... for Ubuntu:
... and for Fedora:
Fixes #153