From 62b9391eec0c56a671af4936da8d4182ca58f000 Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Tue, 25 Jul 2023 06:08:42 -0500 Subject: [PATCH 1/6] Remove a duplicate pre-commit hook --- .pre-commit-config.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a84ea01b01..caef1914c5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,7 +30,6 @@ repos: hooks: - id: no-commit-to-branch args: [--branch, main] - - id: check-toml - id: check-yaml args: [--unsafe] - id: debug-statements From c73899de62888cc3e52c213006cf4bc590f932e8 Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Tue, 25 Jul 2023 06:14:00 -0500 Subject: [PATCH 2/6] Satisfy `check-shebang-scripts-are-executable` pre-commit hook --- .devcontainer/post_create.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/.devcontainer/post_create.sh b/.devcontainer/post_create.sh index c2f86ecd81..c1b3debeac 100644 --- a/.devcontainer/post_create.sh +++ b/.devcontainer/post_create.sh @@ -1,5 +1,3 @@ -#!/bin/bash - sudo apt-get update sudo apt-get install -y libaspell-dev From 5ed3c2901b9a9a17963e13fd2bcf3d767d429087 Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Tue, 25 Jul 2023 06:15:16 -0500 Subject: [PATCH 3/6] Satisfy `mypy` pre-commit hook --- codespell_lib/_codespell.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index bdfd0a6f24..c260e79639 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -554,14 +554,14 @@ def parse_options( import tomllib # type: ignore[import] except ModuleNotFoundError: try: - import tomli as tomllib + import tomli as tomllib # type: ignore[no-redef] except ImportError as e: if tomllib_raise_error: raise ImportError( f"tomllib or tomli are required to read pyproject.toml " f"but could not be imported, got: {e}" ) from None - tomllib = None + tomllib = None # type: ignore[assignment] if tomllib is not None: for toml_file in toml_files: with open(toml_file, "rb") as f: From 81ce5c2ba4ff8b5daa849e63b7a9b0b7dc7d0621 Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Tue, 25 Jul 2023 06:16:44 -0500 Subject: [PATCH 4/6] Run `pre-commit autoupdate` --- .pre-commit-config.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index caef1914c5..932628a25a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -47,7 +47,7 @@ repos: - id: check-case-conflict - id: check-toml - repo: https://github.com/adrienverge/yamllint.git - rev: v1.29.0 + rev: v1.32.0 hooks: - id: yamllint args: @@ -55,30 +55,30 @@ repos: - -d - '{extends: relaxed, rules: {line-length: {max: 90}}}' - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.254 + rev: v0.0.280 hooks: - id: ruff - repo: https://github.com/PyCQA/autoflake - rev: v2.0.1 + rev: v2.2.0 hooks: - id: autoflake - repo: https://github.com/psf/black - rev: 23.1.0 + rev: 23.7.0 hooks: - id: black - repo: https://github.com/codespell-project/codespell - rev: v2.2.2 + rev: v2.2.5 hooks: - id: codespell args: [--toml, pyproject-codespell.precommit-toml] additional_dependencies: - tomli - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.12.1 + rev: v0.13 hooks: - id: validate-pyproject - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.991 + rev: v1.4.1 hooks: - id: mypy args: [--no-warn-unused-ignores, --config-file, pyproject.toml, --disable-error-code, From fc131b31b9fea24fcf1cd05ce7f24f45424577a4 Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Tue, 25 Jul 2023 13:33:14 -0500 Subject: [PATCH 5/6] Resolve mypy config discrepancies between pre-commit and CI In addition, add make target, `mypy`, to run mypy locally. The changes were tested with mypy running on Python 3.7 and Python 3.11. --- .pre-commit-config.yaml | 7 ++----- Makefile | 3 +++ codespell_lib/_codespell.py | 6 +++--- pyproject.toml | 1 + 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 932628a25a..491371d902 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -81,11 +81,8 @@ repos: rev: v1.4.1 hooks: - id: mypy - args: [--no-warn-unused-ignores, --config-file, pyproject.toml, --disable-error-code, - import] + args: ["--config-file", "pyproject.toml"] additional_dependencies: - - chardet - pytest - - pytest-cov - - pytest-dependency + - tomli - types-chardet diff --git a/Makefile b/Makefile index a528e048a3..0c239e5938 100644 --- a/Makefile +++ b/Makefile @@ -59,3 +59,6 @@ pytest: clean: rm -rf codespell.1 + +mypy: + mypy . diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index c260e79639..82973a2860 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -550,9 +550,9 @@ def parse_options( toml_files.append(options.toml) tomllib_raise_error = True if toml_files: - try: - import tomllib # type: ignore[import] - except ModuleNotFoundError: + if sys.version_info >= (3, 11): + import tomllib + else: try: import tomli as tomllib # type: ignore[no-redef] except ImportError as e: diff --git a/pyproject.toml b/pyproject.toml index b9080b2cb3..6d19c8d82f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -98,6 +98,7 @@ expand-star-imports = true pretty = true show_error_codes = true strict = true +warn_unused_ignores = false [tool.pytest.ini_options] addopts = "--cov=codespell_lib -rs --cov-report= --tb=short --junit-xml=junit-results.xml" From 9108082a0da13f67788fdd8de8359d1bd950b555 Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Tue, 25 Jul 2023 13:43:08 -0500 Subject: [PATCH 6/6] Resolve a missing auto-generated file import complaint from mypy --- codespell_lib/__init__.py | 2 +- codespell_lib/_codespell.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/codespell_lib/__init__.py b/codespell_lib/__init__.py index cd77a5534c..4484dbd4fe 100644 --- a/codespell_lib/__init__.py +++ b/codespell_lib/__init__.py @@ -1,4 +1,4 @@ from ._codespell import _script_main, main -from ._version import __version__ +from ._version import __version__ # type: ignore __all__ = ["_script_main", "main", "__version__"] diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index 82973a2860..19999cdbd6 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -26,7 +26,7 @@ from typing import Dict, List, Match, Optional, Pattern, Sequence, Set, Tuple # autogenerated by setuptools_scm -from ._version import __version__ as VERSION # noqa: N812 +from ._version import __version__ as VERSION # type: ignore # noqa: N812 word_regex_def = "[\\w\\-'’`]+" # While we want to treat characters like ( or " as okay for a starting break,