diff options
author | Saif Hakim <saif@benchling.com> | 2021-02-16 01:40:51 -0800 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2021-03-24 10:26:21 +0100 |
commit | 4cdca5f202acdda6c946d5335b2c408be0f87b19 (patch) | |
tree | b9f4ffcb009e1f986d7745920e56bd6d0a40af85 /tests/test_mypy.py | |
parent | 72f8f7214909006c39a2c98c6a65538601b0dd3d (diff) | |
download | rsa-git-saifelse-test-mypy.tar.gz |
Fix hashlib mypy types for Python 3.xsaifelse-test-mypy
As captured in https://github.com/python/typeshed/pull/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:
```
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 #153
Diffstat (limited to 'tests/test_mypy.py')
-rw-r--r-- | tests/test_mypy.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/tests/test_mypy.py b/tests/test_mypy.py index 8258e7e..b13cdcc 100644 --- a/tests/test_mypy.py +++ b/tests/test_mypy.py @@ -1,4 +1,5 @@ import pathlib +import sys import unittest import mypy.api @@ -9,8 +10,11 @@ test_modules = ['rsa', 'tests'] class MypyRunnerTest(unittest.TestCase): def test_run_mypy(self): proj_root = pathlib.Path(__file__).parent.parent - args = ['--incremental', '--ignore-missing-imports'] + [str(proj_root / dirname) for dirname - in test_modules] + args = [ + '--incremental', + '--ignore-missing-imports', + f'--python-version={sys.version_info.major}.{sys.version_info.minor}' + ] + [str(proj_root / dirname) for dirname in test_modules] result = mypy.api.run(args) |