From 1efce5fd55dee66361c7ca23ac03c87c9de65501 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Wed, 2 Jun 2021 09:11:46 +0100 Subject: [PATCH] Fixed typing pip 21.0 has internal changes that break at least our typing and we will need signifiant changes to support 21.x. For the moment we ceil pip version and assure running mypy does get us consistent results inside and outside pre-commit. Fixes type change introduced by click 8 --- .pre-commit-config.yaml | 6 ++++++ piptools/scripts/compile.py | 8 +++++--- setup.cfg | 4 ++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1ae629890..7fbec780b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,7 +25,13 @@ repos: - id: mypy # Avoid error: Duplicate module named 'setup' # https://github.com/python/mypy/issues/4008 + # Keep exclude in sync with mypy own excludes exclude: ^tests/test_data/ + additional_dependencies: + - click==8.0.1 + - pep517==0.10.0 + - toml==0.10.2 + - pip==20.3.4 - repo: https://github.com/PyCQA/bandit rev: 1.7.0 hooks: diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index b880b80eb..d319e5115 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -2,7 +2,7 @@ import shlex import sys import tempfile -from typing import Any, BinaryIO, List, Optional, Tuple, cast +from typing import IO, Any, BinaryIO, List, Optional, Tuple, Union, cast import click from click.utils import LazyFile, safecall @@ -231,7 +231,7 @@ def cli( annotate: bool, upgrade: bool, upgrade_packages: Tuple[str, ...], - output_file: Optional[LazyFile], + output_file: Union[LazyFile, IO[Any], None], allow_unsafe: bool, generate_hashes: bool, reuse_hashes: bool, @@ -282,7 +282,9 @@ def cli( # Close the file at the end of the context execution assert output_file is not None - ctx.call_on_close(safecall(output_file.close_intelligently)) + # only LazyFile has close_intelligently, newer IO[Any] does not + if isinstance(output_file, LazyFile): # pragma: no cover + ctx.call_on_close(safecall(output_file.close_intelligently)) ### # Setup diff --git a/setup.cfg b/setup.cfg index dc29b0f09..e6b12f724 100644 --- a/setup.cfg +++ b/setup.cfg @@ -93,5 +93,9 @@ warn_return_any = true warn_unused_configs = true warn_unused_ignores = true +# Avoid error: Duplicate module named 'setup' +# https://github.com/python/mypy/issues/4008 +exclude = ^tests/test_data/ + [mypy-tests.*] disallow_untyped_defs = false