From 8474158155bce5f417e01066d2f58d66792ac832 Mon Sep 17 00:00:00 2001 From: Ilan Schnell Date: Fri, 11 Jun 2021 22:35:42 -0500 Subject: [PATCH] add make mypy to Makefile --- Makefile | 4 ++++ bitarray/__init__.pyi | 6 +++--- bitarray/test_bitarray.py | 6 +++--- bitarray/test_util.py | 2 +- bitarray/util.pyi | 6 +++--- examples/hexadecimal.py | 4 ++-- examples/mandel.py | 2 +- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 507400fe..2e735f34 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,10 @@ doc: bitarray/_bitarray.so twine check dist/* +mypy: + mypy examples/*.py examples/huffman/*.py + + clean: rm -rf build dist rm -f bitarray/*.o bitarray/*.so diff --git a/bitarray/__init__.pyi b/bitarray/__init__.pyi index 58e9e29b..692bba32 100644 --- a/bitarray/__init__.pyi +++ b/bitarray/__init__.pyi @@ -1,14 +1,14 @@ """ This stub, as well as util.pyi, have been tested with -Python 3.9 and mypy 0.901 +Python 3.9 and mypy 0.902 """ from collections.abc import Iterable, Iterator from unittest.runner import TextTestResult -from typing import BinaryIO, Hashable, Union, overload +from typing import Any, BinaryIO, Union, overload -Codedict = dict[Hashable, bitarray] +Codedict = dict[Any, bitarray] class decodetree: diff --git a/bitarray/test_bitarray.py b/bitarray/test_bitarray.py index da32fa29..12b07319 100644 --- a/bitarray/test_bitarray.py +++ b/bitarray/test_bitarray.py @@ -25,8 +25,8 @@ if is_py3k: from io import BytesIO else: - from cStringIO import StringIO as BytesIO - range = xrange + from cStringIO import StringIO as BytesIO # type: ignore + range = xrange # type: ignore from bitarray import (bitarray, frozenbitarray, bits2bytes, decodetree, @@ -40,7 +40,7 @@ def zeros(n, endian=None): a.setall(0) return a -tests = [] +tests = [] # type: list class Util(object): diff --git a/bitarray/test_util.py b/bitarray/test_util.py index 560a7a25..6ff84b1e 100644 --- a/bitarray/test_util.py +++ b/bitarray/test_util.py @@ -30,7 +30,7 @@ else: from io import BytesIO as StringIO -tests = [] +tests = [] # type: list # --------------------------------------------------------------------------- diff --git a/bitarray/util.pyi b/bitarray/util.pyi index 08307a5b..bbf28310 100644 --- a/bitarray/util.pyi +++ b/bitarray/util.pyi @@ -1,4 +1,4 @@ -from typing import Any, AnyStr, BinaryIO, Hashable, Optional, Union +from typing import Any, AnyStr, BinaryIO, Optional, Union from bitarray import bitarray @@ -38,6 +38,6 @@ def int2ba(i: int, /, def serialize(a: bitarray, /) -> bytes: ... def deserialize(b: bytes, /) -> bitarray: ... -def huffman_code(freq_map: dict[Hashable, Union[int, float]], +def huffman_code(freq_map: dict[Any, Union[int, float]], endian: Optional[str] = ... - ) -> dict[Hashable, bitarray]: ... + ) -> dict[Any, bitarray]: ... diff --git a/examples/hexadecimal.py b/examples/hexadecimal.py index d23a31a2..c7792748 100644 --- a/examples/hexadecimal.py +++ b/examples/hexadecimal.py @@ -16,8 +16,8 @@ 'c': bitarray('1100'), 'd': bitarray('1101'), 'e': bitarray('1110'), 'f': bitarray('1111'), }} -for k, v in CODEDICT['big'].items(): - CODEDICT['little'][k] = v[::-1] +for k, v in CODEDICT['big'].items(): # type: ignore + CODEDICT['little'][k] = v[::-1] # type: ignore def prefix_ba2hex(a): return ''.join(a.iterdecode(CODEDICT[a.endian()])) diff --git a/examples/mandel.py b/examples/mandel.py index f574939e..2f72bd60 100644 --- a/examples/mandel.py +++ b/examples/mandel.py @@ -1,6 +1,6 @@ import sys from bitarray import bitarray -from numba import jit +from numba import jit # type: ignore width, height = 4000, 3000 maxdepth = 500