From d7423df58daff405d900b7dd9257b981fbdbcd18 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Wed, 15 Sep 2021 20:06:01 +0100 Subject: [PATCH] set up mypy hook for incremental adoption --- .pre-commit-config.yaml | 15 +++++++++++++++ mypy.ini | 37 ++++++++++++++++++++++++++++++++++++ poetry/__init__.py | 3 ++- poetry/core/utils/helpers.py | 9 +++------ 4 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 mypy.ini diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b9e58d676..a1e5e307a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,6 +16,21 @@ repos: | ^poetry/core/_vendor ) + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.910 + hooks: + - id: mypy + additional_dependencies: + - types-requests + files: | + (?x)( + ^poetry + ) + exclude: | + (?x)( + ^poetry/core/_vendor + ) + - repo: https://github.com/pycqa/isort rev: 5.9.3 hooks: diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 000000000..4e119c252 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,37 @@ +[mypy] +follow_imports = silent + +# The following whitelist is used to allow for incremental adoption +# of Mypy. Modules should be removed from this whitelist as and when +# their respective type errors have been addressed. No new modules +# should be added to this whitelist. +# see https://github.com/python-poetry/poetry-core/pull/199. + +[mypy-poetry.core.factory.*] +ignore_errors = True + +[mypy-poetry.core.masonry.*] +ignore_errors = True + +[mypy-poetry.core.packages.*] +ignore_errors = True + +[mypy-poetry.core.poetry.*] +ignore_errors = True + +[mypy-poetry.core.pyproject.*] +ignore_errors = True + +[mypy-poetry.core.semver.*] +ignore_errors = True + +[mypy-poetry.core.spdx.*] +ignore_errors = True + +[mypy-poetry.core.vcs.*] +ignore_errors = True + +[mypy-poetry.core.version.*] +ignore_errors = True + +# end of whitelist diff --git a/poetry/__init__.py b/poetry/__init__.py index 26cfe4052..0bd1cd515 100644 --- a/poetry/__init__.py +++ b/poetry/__init__.py @@ -1,4 +1,5 @@ from pkgutil import extend_path +from typing import List -__path__ = extend_path(__path__, __name__) +__path__: List[str] = extend_path(__path__, __name__) diff --git a/poetry/core/utils/helpers.py b/poetry/core/utils/helpers.py index 9eb47e6fd..a6eaa195e 100644 --- a/poetry/core/utils/helpers.py +++ b/poetry/core/utils/helpers.py @@ -4,22 +4,18 @@ import stat import tempfile +from collections.abc import Mapping from contextlib import contextmanager from pathlib import Path from typing import Any from typing import Iterator from typing import List from typing import Union +from typing import no_type_check from poetry.core.version.pep440 import PEP440Version -try: - from collections.abc import Mapping -except ImportError: - from collections import Mapping - - _canonicalize_regex = re.compile(r"[-_]+") @@ -42,6 +38,7 @@ def temporary_directory(*args: Any, **kwargs: Any) -> Iterator[str]: safe_rmtree(name) +@no_type_check def parse_requires(requires: str) -> List[str]: lines = requires.split("\n")