From 05ac83c4089d69a13337ccc1ae8a9ab0826d5a5d Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Sat, 18 Nov 2023 13:14:15 +0000 Subject: [PATCH 1/3] Upgrade mypy to 1.7.0 --- .pre-commit-config.yaml | 2 +- CHANGES.md | 2 +- pyproject.toml | 4 ++-- scripts/check_pre_commit_rev_in_example.py | 2 +- scripts/check_version_in_basics_example.py | 2 +- scripts/diff_shades_gha_helper.py | 2 +- scripts/fuzz.py | 2 +- scripts/make_width_table.py | 2 +- src/blackd/__init__.py | 4 +--- src/blib2to3/pgen2/tokenize.py | 6 ++---- tests/optional.py | 10 +++++++++- 11 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 623e661ac07..230f2b7e796 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,7 +39,7 @@ repos: exclude: ^src/blib2to3/ - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.5.1 + rev: v1.7.0 hooks: - id: mypy exclude: ^docs/conf.py diff --git a/CHANGES.md b/CHANGES.md index 9446927b8d1..bf8066aff24 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -20,7 +20,7 @@ ### Packaging - +- Upgrade to mypy 1.7.0 (#4049) ### Parser diff --git a/pyproject.toml b/pyproject.toml index c0302d2302a..571f13a8ecd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -120,7 +120,7 @@ macos-max-compat = true enable-by-default = false dependencies = [ "hatch-mypyc>=0.16.0", - "mypy==1.5.1", + "mypy==1.7.0", "click==8.1.3", # avoid https://github.com/pallets/click/issues/2558 ] require-runtime-dependencies = true @@ -186,7 +186,7 @@ CC = "clang" build-frontend = { name = "build", args = ["--no-isolation"] } # Unfortunately, hatch doesn't respect MACOSX_DEPLOYMENT_TARGET before-build = [ - "python -m pip install 'hatchling==1.18.0' hatch-vcs hatch-fancy-pypi-readme 'hatch-mypyc>=0.16.0' 'mypy==1.5.1' 'click==8.1.3'", + "python -m pip install 'hatchling==1.18.0' hatch-vcs hatch-fancy-pypi-readme 'hatch-mypyc>=0.16.0' 'mypy==1.7.0' 'click==8.1.3'", """sed -i '' -e "600,700s/'10_16'/os.environ['MACOSX_DEPLOYMENT_TARGET'].replace('.', '_')/" $(python -c 'import hatchling.builders.wheel as h; print(h.__file__)') """, ] diff --git a/scripts/check_pre_commit_rev_in_example.py b/scripts/check_pre_commit_rev_in_example.py index 107c6444dca..cc45a31e1ed 100644 --- a/scripts/check_pre_commit_rev_in_example.py +++ b/scripts/check_pre_commit_rev_in_example.py @@ -14,7 +14,7 @@ import commonmark import yaml -from bs4 import BeautifulSoup # type: ignore[import] +from bs4 import BeautifulSoup # type: ignore[import-untyped] def main(changes: str, source_version_control: str) -> None: diff --git a/scripts/check_version_in_basics_example.py b/scripts/check_version_in_basics_example.py index 0f42bafe334..c90fdb43da5 100644 --- a/scripts/check_version_in_basics_example.py +++ b/scripts/check_version_in_basics_example.py @@ -8,7 +8,7 @@ import sys import commonmark -from bs4 import BeautifulSoup # type: ignore[import] +from bs4 import BeautifulSoup # type: ignore[import-untyped] def main(changes: str, the_basics: str) -> None: diff --git a/scripts/diff_shades_gha_helper.py b/scripts/diff_shades_gha_helper.py index 895516deb51..8cd8ba155ce 100644 --- a/scripts/diff_shades_gha_helper.py +++ b/scripts/diff_shades_gha_helper.py @@ -119,7 +119,7 @@ def main() -> None: @main.command("config", help="Acquire run configuration and metadata.") @click.argument("event", type=click.Choice(["push", "pull_request"])) def config(event: Literal["push", "pull_request"]) -> None: - import diff_shades # type: ignore[import] + import diff_shades # type: ignore[import-not-found] if event == "push": jobs = [{"mode": "preview-changes", "force-flag": "--force-preview-style"}] diff --git a/scripts/fuzz.py b/scripts/fuzz.py index 929d3eac4f5..018b66e0ea2 100644 --- a/scripts/fuzz.py +++ b/scripts/fuzz.py @@ -80,7 +80,7 @@ def test_idempotent_any_syntatically_valid_python( try: import sys - import atheris # type: ignore[import] + import atheris # type: ignore[import-not-found] except ImportError: pass else: diff --git a/scripts/make_width_table.py b/scripts/make_width_table.py index 3c7cae60f7f..1b53c1b2cc9 100644 --- a/scripts/make_width_table.py +++ b/scripts/make_width_table.py @@ -20,7 +20,7 @@ from os.path import basename, dirname, join from typing import Iterable, Tuple -import wcwidth # type: ignore[import] +import wcwidth # type: ignore[import-not-found] def make_width_table() -> Iterable[Tuple[int, int, int]]: diff --git a/src/blackd/__init__.py b/src/blackd/__init__.py index 972f24181cb..6b0f3d33295 100644 --- a/src/blackd/__init__.py +++ b/src/blackd/__init__.py @@ -74,9 +74,7 @@ def main(bind_host: str, bind_port: int) -> None: app = make_app() ver = black.__version__ black.out(f"blackd version {ver} listening on {bind_host} port {bind_port}") - # TODO: aiohttp had an incorrect annotation for `print` argument, - # It'll be fixed once aiohttp releases that code - web.run_app(app, host=bind_host, port=bind_port, handle_signals=True, print=None) # type: ignore[arg-type] + web.run_app(app, host=bind_host, port=bind_port, handle_signals=True, print=None) def make_app() -> web.Application: diff --git a/src/blib2to3/pgen2/tokenize.py b/src/blib2to3/pgen2/tokenize.py index d0607f4b1e1..3191ab96ad6 100644 --- a/src/blib2to3/pgen2/tokenize.py +++ b/src/blib2to3/pgen2/tokenize.py @@ -262,11 +262,9 @@ def add_whitespace(self, start: Coord) -> None: def untokenize(self, iterable: Iterable[TokenInfo]) -> str: for t in iterable: if len(t) == 2: - self.compat(cast(Tuple[int, str], t), iterable) + self.compat(t, iterable) break - tok_type, token, start, end, line = cast( - Tuple[int, str, Coord, Coord, str], t - ) + tok_type, token, start, end, line = t self.add_whitespace(start) self.tokens.append(token) self.prev_row, self.prev_col = end diff --git a/tests/optional.py b/tests/optional.py index 3f5277b6b03..26475890217 100644 --- a/tests/optional.py +++ b/tests/optional.py @@ -26,7 +26,15 @@ from pytest import StashKey except ImportError: # pytest < 7 - from _pytest.store import StoreKey as StashKey # type: ignore[import, no-redef] + # + # "isort: skip" is needed or it moves the "type: ignore" to the following line + # becuase of the line length, and then mypy complains. + # Of course, adding the "isort: skip" means that + # flake8-bugbear then also complains about the line length, + # so we *also* need a "noqa" comment for good measure :) + from _pytest.store import ( # type: ignore[import-not-found, no-redef] # isort: skip # noqa: B950 + StoreKey as StashKey, + ) log = logging.getLogger(__name__) From 35a1d55b835acd963e2dd9b1f5470be9a8f292f8 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Sat, 18 Nov 2023 13:56:34 +0000 Subject: [PATCH 2/3] just do 1.6.1 for now --- .pre-commit-config.yaml | 2 +- CHANGES.md | 2 +- pyproject.toml | 4 ++-- src/blib2to3/pgen2/tokenize.py | 6 ++++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 230f2b7e796..c153746b621 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,7 +39,7 @@ repos: exclude: ^src/blib2to3/ - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.7.0 + rev: v1.6.1 hooks: - id: mypy exclude: ^docs/conf.py diff --git a/CHANGES.md b/CHANGES.md index bf8066aff24..13b6c7bdb21 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -20,7 +20,7 @@ ### Packaging -- Upgrade to mypy 1.7.0 (#4049) +- Upgrade to mypy 1.6.1 (#4049) ### Parser diff --git a/pyproject.toml b/pyproject.toml index 571f13a8ecd..9d269ac54ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -120,7 +120,7 @@ macos-max-compat = true enable-by-default = false dependencies = [ "hatch-mypyc>=0.16.0", - "mypy==1.7.0", + "mypy==1.6.1", "click==8.1.3", # avoid https://github.com/pallets/click/issues/2558 ] require-runtime-dependencies = true @@ -186,7 +186,7 @@ CC = "clang" build-frontend = { name = "build", args = ["--no-isolation"] } # Unfortunately, hatch doesn't respect MACOSX_DEPLOYMENT_TARGET before-build = [ - "python -m pip install 'hatchling==1.18.0' hatch-vcs hatch-fancy-pypi-readme 'hatch-mypyc>=0.16.0' 'mypy==1.7.0' 'click==8.1.3'", + "python -m pip install 'hatchling==1.18.0' hatch-vcs hatch-fancy-pypi-readme 'hatch-mypyc>=0.16.0' 'mypy==1.6.1' 'click==8.1.3'", """sed -i '' -e "600,700s/'10_16'/os.environ['MACOSX_DEPLOYMENT_TARGET'].replace('.', '_')/" $(python -c 'import hatchling.builders.wheel as h; print(h.__file__)') """, ] diff --git a/src/blib2to3/pgen2/tokenize.py b/src/blib2to3/pgen2/tokenize.py index 3191ab96ad6..d0607f4b1e1 100644 --- a/src/blib2to3/pgen2/tokenize.py +++ b/src/blib2to3/pgen2/tokenize.py @@ -262,9 +262,11 @@ def add_whitespace(self, start: Coord) -> None: def untokenize(self, iterable: Iterable[TokenInfo]) -> str: for t in iterable: if len(t) == 2: - self.compat(t, iterable) + self.compat(cast(Tuple[int, str], t), iterable) break - tok_type, token, start, end, line = t + tok_type, token, start, end, line = cast( + Tuple[int, str, Coord, Coord, str], t + ) self.add_whitespace(start) self.tokens.append(token) self.prev_row, self.prev_col = end From 2c1bac75de5c0a18996bdd0e9d8bcb892a508dc3 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 18 Nov 2023 07:14:32 -0800 Subject: [PATCH 3/3] Update tests/optional.py --- tests/optional.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/optional.py b/tests/optional.py index 26475890217..70ee823e316 100644 --- a/tests/optional.py +++ b/tests/optional.py @@ -28,7 +28,7 @@ # pytest < 7 # # "isort: skip" is needed or it moves the "type: ignore" to the following line - # becuase of the line length, and then mypy complains. + # because of the line length, and then mypy complains. # Of course, adding the "isort: skip" means that # flake8-bugbear then also complains about the line length, # so we *also* need a "noqa" comment for good measure :)