Skip to content

Commit 772a17c

Browse files
committed
Drop Py3.8 support, enable strict mypy and address
1 parent 53ae81c commit 772a17c

File tree

7 files changed

+54
-43
lines changed

7 files changed

+54
-43
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ repos:
4545
- .
4646
args:
4747
[--no-strict-optional, --ignore-missing-imports, --show-error-codes]
48+
exclude: tests/

pyproject.toml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ build-backend = "hatchling.build"
66
name = "pre_commit_hooks"
77
description = "A selection of pre-commit hooks for pre-commit.com."
88
readme = "README.md"
9-
requires-python = ">=3.8"
9+
requires-python = ">=3.10"
1010
license = "GPL-3.0-or-later"
1111
keywords = ["pre-commit"]
1212
authors = [{ name = "adehad", email = "26027314+adehad@users.noreply.github.com" }]
1313
classifiers = [
1414
"Development Status :: 4 - Beta",
1515
"Programming Language :: Python",
16-
"Programming Language :: Python :: 3.8",
17-
"Programming Language :: Python :: 3.9",
1816
"Programming Language :: Python :: 3.10",
1917
"Programming Language :: Python :: 3.11",
2018
"Programming Language :: Python :: Implementation :: CPython",
@@ -67,19 +65,20 @@ lint = "python -m pre_commit run --color=always {args:--all-files}"
6765
# Tests
6866
########################################################################################
6967
[[tool.hatch.envs.test.matrix]]
70-
python = ["38", "39", "310", "311"]
68+
python = ["310", "311"]
7169

7270
########################################################################################
7371
# External Tool Config
7472
########################################################################################
7573
[tool.mypy]
76-
python_version = '3.8'
74+
python_version = '3.10'
7775
strict = true
7876
ignore_missing_imports = true
7977
namespace_packages = true
8078
show_error_codes = true
8179
strict_optional = true
8280
warn_unused_configs = true
81+
exclude = ["tests/"]
8382

8483
[tool.coverage.run]
8584
branch = true
@@ -89,7 +88,7 @@ omit = ["src/pre_commit_hooks/__about__.py"]
8988
[tool.coverage.report]
9089
exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"]
9190

92-
[tool.ruff]
91+
[tool.ruff.lint]
9392
select = [
9493
"E", # pycodestyle
9594
"W", # pycodestyle
@@ -101,22 +100,23 @@ select = [
101100
]
102101
ignore = []
103102

104-
# Same as Black.
105-
line-length = 88
106-
107103
# Allow unused variables when underscore-prefixed.
108104
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
109105

110-
# Assume Python 3.8. (minimum supported)
111-
target-version = "py38"
106+
[tool.ruff]
107+
# Same as Black.
108+
line-length = 88
109+
110+
# Assume Python 3.10. (minimum supported)
111+
target-version = "py310"
112112

113113
# The source code paths to consider, e.g., when resolving first- vs. third-party imports
114114
src = ["pre_commit_hooks", "tests"]
115115

116-
[tool.ruff.isort]
116+
[tool.ruff.lint.isort]
117117
known-first-party = ["pre_commit_hooks", "tests"]
118118
required-imports = ["from __future__ import annotations"]
119119

120-
[tool.ruff.pydocstyle]
120+
[tool.ruff.lint.pydocstyle]
121121
# Use Google-style docstrings.
122122
convention = "google"

src/pre_commit_hooks/arabic_presentation_form/__init__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import pathlib
77
import re
88
import sys
9-
from typing import Any, Dict, Sequence
9+
from collections.abc import Sequence
10+
from typing import Any
1011

1112
from ..util import (
1213
ABCArgs,
@@ -17,16 +18,18 @@
1718
)
1819
from . import char_map
1920

20-
sys.stdout.reconfigure(encoding="utf-8") # For Windows: we want to be sure to use UTF-8
21-
RulesDict = Dict[re.Pattern[Any], str]
21+
sys.stdout.reconfigure( # type: ignore[attr-defined]
22+
encoding="utf-8" # For Windows: we want to be sure to use UTF-8
23+
)
24+
RulesDict = dict[re.Pattern[Any], str]
2225

2326

2427
def apply_rules_to_lines(
2528
line: str,
2629
rules: RulesDict,
27-
exclude: re.Pattern,
28-
file_name: str,
29-
line_no: str,
30+
exclude: re.Pattern[str],
31+
file_name: pathlib.Path | str,
32+
line_no: str | int,
3033
) -> tuple[ExitCode, str]:
3134
"""Check the text for rules.
3235
@@ -73,7 +76,7 @@ def apply_rules_to_lines(
7376
return exit_code, new_line
7477

7578

76-
def get_rules(custom_rules: dict[str, dict[str, str]]) -> RulesDict:
79+
def get_rules(custom_rules: char_map.CHAR_MAP_TYPE) -> RulesDict:
7780
"""Return the rules from a given config string.
7881
7982
Args:

src/pre_commit_hooks/arabic_presentation_form/char_map.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
import enum
99

10-
CHAR_MAP_TYPE = dict[str, dict[str, dict[str, str]]]
10+
REMAP_RULE_TYPE = dict[str, dict[str, str]]
11+
CHAR_MAP_TYPE = dict[str, REMAP_RULE_TYPE]
1112

1213
# spell-checker: disable
1314
# ruff: noqa: E501, RUF001, RUF003
@@ -84,32 +85,33 @@ class ArabicUnicodeGroup(enum.Enum):
8485
"""143 characters"""
8586

8687
@classmethod
87-
def get_type(cls: ArabicUnicodeGroup, input_char: str) -> ArabicUnicodeGroup:
88+
def get_type(cls: type[ArabicUnicodeGroup], input_char: str) -> ArabicUnicodeGroup:
8889
"""Return the Arabic Unicode Group."""
90+
unicode_group = cls.Unknown
8991
if "\u0600" <= input_char <= "\u06ff":
90-
return cls.Arabic
92+
unicode_group = cls.Arabic
9193
elif "\u0750" <= input_char <= "\u077f":
92-
return cls.ArabicSupplement
94+
unicode_group = cls.ArabicSupplement
9395
elif "\u0870" <= input_char <= "\u089f":
94-
return cls.ArabicExtendedB
96+
unicode_group = cls.ArabicExtendedB
9597
elif "\u08a0" <= input_char <= "\u08ff":
96-
return cls.ArabicExtendedA
98+
unicode_group = cls.ArabicExtendedA
9799
elif "\ufb50" <= input_char <= "\ufdff":
98-
return cls.ArabicPresentationFormsA
100+
unicode_group = cls.ArabicPresentationFormsA
99101
elif "\ufe70" <= input_char <= "\ufeff":
100-
return cls.ArabicPresentationFormsB
102+
unicode_group = cls.ArabicPresentationFormsB
101103
elif "\u10e60" <= input_char <= "\u10e7F":
102-
return cls.RumiNumeralSymbols
104+
unicode_group = cls.RumiNumeralSymbols
103105
elif "\u10ec0" <= input_char <= "\u10efF":
104-
return cls.ArabicExtendedC
106+
unicode_group = cls.ArabicExtendedC
105107
elif "\u1ec70" <= input_char <= "\u1ecbF":
106-
return cls.IndicSiyaqNumbers
108+
unicode_group = cls.IndicSiyaqNumbers
107109
elif "\u1ed00" <= input_char <= "\u1ed4F":
108-
return cls.OttomanSiyaqNumbers
110+
unicode_group = cls.OttomanSiyaqNumbers
109111
elif "\u1ee00" <= input_char <= "\u1eefF":
110-
return cls.ArabicMathematicalAlphabeticSymbols
111-
else:
112-
return cls.Unknown
112+
unicode_group = cls.ArabicMathematicalAlphabeticSymbols
113+
114+
return unicode_group
113115

114116

115117
def is_contains_non_general_form(char: str) -> bool:

src/pre_commit_hooks/check_header_footer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import json
88
import pathlib
99
import re
10-
from typing import Any, Dict, NamedTuple, Sequence
10+
from collections.abc import Sequence
11+
from typing import Any, NamedTuple
1112

1213
from .util import (
1314
ABCArgs,
@@ -17,7 +18,7 @@
1718
sanitize_rb_line,
1819
)
1920

20-
RulesDict = Dict[str, re.Pattern[Any]]
21+
RulesDict = dict[str, re.Pattern[Any]]
2122

2223

2324
def check_rules_in_file(

src/pre_commit_hooks/util.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import json
1010
import os
1111
import pathlib
12-
from typing import Any, Sequence
12+
import typing
13+
from collections.abc import Sequence
14+
from typing import Any
1315

1416

1517
class ExitCode(enum.IntEnum):
@@ -108,21 +110,22 @@ def load_json_source(file_or_json_str: str) -> dict[str, Any]:
108110
Returns:
109111
dict[str, Any]: Loaded JSON.
110112
"""
113+
default: dict[str, Any] = {}
111114
file_source = pathlib.Path(file_or_json_str)
112115
if file_source.is_file():
113116
with file_source.open(encoding="utf-8") as fp:
114-
return json.load(fp)
117+
return typing.cast(dict[str, Any], json.load(fp))
115118

116119
try:
117-
return json.loads(file_or_json_str)
120+
return json.loads(file_or_json_str) # type: ignore[no-any-return]
118121
except Exception:
119122
print("Unsupported JSON source, no custom rules applied!")
120-
return {}
123+
return default
121124

122125

123-
class HashableDict(dict):
126+
class HashableDict(dict): # type: ignore[type-arg]
124127
"""Hashable dict but not immutable."""
125128

126-
def __hash__(self) -> int:
129+
def __hash__(self) -> int: # type: ignore[override]
127130
"""Hash."""
128131
return hash((frozenset(self), frozenset(self.values())))

tests/ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
extend = "../pyproject.toml"
2+
[lint]
23
ignore = [
34
"D", # Allow undocumented test functions
45
]

0 commit comments

Comments
 (0)