diff --git a/.gitignore b/.gitignore --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ kafka*.tar.gz* swh/journal/tests/kafka* .hypothesis/ +.mypy_cache/ diff --git a/MANIFEST.in b/MANIFEST.in --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,3 +2,4 @@ include requirements.txt include requirements-swh.txt include version.txt +recursive-include swh py.typed diff --git a/mypy.ini b/mypy.ini new file mode 100644 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,21 @@ +[mypy] +namespace_packages = True +warn_unused_ignores = True + + +# 3rd party libraries without stubs (yet) + +[mypy-confluent_kafka.*] +ignore_missing_imports = True + +[mypy-msgpack.*] +ignore_missing_imports = True + +[mypy-pkg_resources.*] +ignore_missing_imports = True + +[mypy-pytest.*] +ignore_missing_imports = True + +[mypy-pytest_kafka.*] +ignore_missing_imports = True diff --git a/swh/__init__.py b/swh/__init__.py --- a/swh/__init__.py +++ b/swh/__init__.py @@ -1 +1,4 @@ -__path__ = __import__('pkgutil').extend_path(__path__, __name__) +from pkgutil import extend_path +from typing import Iterable + +__path__ = extend_path(__path__, __name__) # type: Iterable[str] diff --git a/swh/journal/py.typed b/swh/journal/py.typed new file mode 100644 --- /dev/null +++ b/swh/journal/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561. diff --git a/swh/journal/tests/conftest.py b/swh/journal/tests/conftest.py --- a/swh/journal/tests/conftest.py +++ b/swh/journal/tests/conftest.py @@ -11,7 +11,7 @@ from confluent_kafka import Consumer from subprocess import Popen -from typing import Tuple, Dict +from typing import Any, Dict, List, Optional, Tuple from pathlib import Path from pytest_kafka import ( @@ -154,7 +154,7 @@ 'release': ('id', RELEASES), 'origin': (None, ORIGINS), 'origin_visit': (None, ORIGIN_VISITS), -} +} # type: Dict[str, Tuple[Optional[str], List[Dict[str, Any]]]] KAFKA_ROOT = os.environ.get('SWH_KAFKA_ROOT') diff --git a/swh/journal/tests/test_cli.py b/swh/journal/tests/test_cli.py --- a/swh/journal/tests/test_cli.py +++ b/swh/journal/tests/test_cli.py @@ -8,7 +8,7 @@ import re import tempfile from subprocess import Popen -from typing import Tuple +from typing import Any, Dict, Tuple from unittest.mock import patch from click.testing import CliRunner @@ -81,7 +81,7 @@ 'target_type': 'revision', 'target': b'\x01'*20, } - }} + }} # type: Dict[str, Any] producer.produce( topic=kafka_prefix+'.snapshot', key=key_to_kafka(snapshot['id']), diff --git a/tox.ini b/tox.ini --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist=flake8,py3-no-origin-ids,py3 +envlist=flake8,mypy,py3-no-origin-ids,py3 [testenv:py3] passenv=SWH_KAFKA_ROOT @@ -25,3 +25,11 @@ flake8 commands = {envpython} -m flake8 + +[testenv:mypy] +skip_install = true +deps = + .[testing] + mypy +commands = + mypy swh