Skip to content

Commit fb2ba03

Browse files
Avoid deprecated license specification format (#3723)
1 parent 5d74860 commit fb2ba03

File tree

7 files changed

+58
-70
lines changed

7 files changed

+58
-70
lines changed

.github/workflows/tests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ jobs:
2020
fail-fast: false
2121
matrix:
2222
python-version:
23-
- "3.8"
2423
- "3.9"
2524
- "3.10"
2625
- "3.11"

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Useful links
2020
Requirements
2121
------------
2222

23-
Python 3.8 or above.
23+
Python 3.9 or above.
2424

2525
Installation
2626
------------

codespell_lib/_codespell.py

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,12 @@
2525
import re
2626
import sys
2727
import textwrap
28+
from collections.abc import Iterable, Sequence
29+
from re import Match, Pattern
2830
from typing import (
2931
Any,
30-
Dict,
31-
Iterable,
32-
List,
33-
Match,
3432
Optional,
35-
Pattern,
36-
Sequence,
37-
Set,
3833
TextIO,
39-
Tuple,
4034
)
4135

4236
if sys.platform == "win32":
@@ -161,8 +155,8 @@ class QuietLevels:
161155

162156

163157
class GlobMatch:
164-
def __init__(self, pattern: List[str]) -> None:
165-
self.pattern_list: List[str] = pattern
158+
def __init__(self, pattern: list[str]) -> None:
159+
self.pattern_list: list[str] = pattern
166160

167161
def match(self, filename: str) -> bool:
168162
return any(fnmatch.fnmatch(filename, p) for p in self.pattern_list)
@@ -184,7 +178,7 @@ def disable(self) -> None:
184178

185179
class Summary:
186180
def __init__(self) -> None:
187-
self.summary: Dict[str, int] = {}
181+
self.summary: dict[str, int] = {}
188182

189183
def update(self, wrongword: str) -> None:
190184
if wrongword in self.summary:
@@ -227,12 +221,12 @@ def init_chardet(self) -> None:
227221

228222
self.encdetector = UniversalDetector()
229223

230-
def open(self, filename: str) -> Tuple[List[str], str]:
224+
def open(self, filename: str) -> tuple[list[str], str]:
231225
if self.use_chardet:
232226
return self.open_with_chardet(filename)
233227
return self.open_with_internal(filename)
234228

235-
def open_with_chardet(self, filename: str) -> Tuple[List[str], str]:
229+
def open_with_chardet(self, filename: str) -> tuple[list[str], str]:
236230
self.encdetector.reset()
237231
with open(filename, "rb") as fb:
238232
for line in fb:
@@ -259,7 +253,7 @@ def open_with_chardet(self, filename: str) -> Tuple[List[str], str]:
259253

260254
return lines, f.encoding
261255

262-
def open_with_internal(self, filename: str) -> Tuple[List[str], str]:
256+
def open_with_internal(self, filename: str) -> tuple[list[str], str]:
263257
encoding = None
264258
first_try = True
265259
for encoding in ("utf-8", "iso-8859-1"):
@@ -286,7 +280,7 @@ def open_with_internal(self, filename: str) -> Tuple[List[str], str]:
286280

287281
return lines, encoding
288282

289-
def get_lines(self, f: TextIO) -> List[str]:
283+
def get_lines(self, f: TextIO) -> list[str]:
290284
if self.ignore_multiline_regex:
291285
text = f.read()
292286
pos = 0
@@ -313,7 +307,7 @@ def get_lines(self, f: TextIO) -> List[str]:
313307
class NewlineHelpFormatter(argparse.HelpFormatter):
314308
"""Help formatter that preserves newlines and deals with lists."""
315309

316-
def _split_lines(self, text: str, width: int) -> List[str]:
310+
def _split_lines(self, text: str, width: int) -> list[str]:
317311
parts = text.split("\n")
318312
out = []
319313
for part in parts:
@@ -330,7 +324,7 @@ def _split_lines(self, text: str, width: int) -> List[str]:
330324
return out
331325

332326

333-
def _toml_to_parseconfig(toml_dict: Dict[str, Any]) -> Dict[str, Any]:
327+
def _toml_to_parseconfig(toml_dict: dict[str, Any]) -> dict[str, Any]:
334328
"""Convert a dict read from a TOML file to the parseconfig.read_dict() format."""
335329
return {
336330
k: "" if v is True else ",".join(v) if isinstance(v, list) else v
@@ -373,7 +367,7 @@ def _supports_ansi_colors() -> bool:
373367

374368
def parse_options(
375369
args: Sequence[str],
376-
) -> Tuple[argparse.Namespace, argparse.ArgumentParser, List[str]]:
370+
) -> tuple[argparse.Namespace, argparse.ArgumentParser, list[str]]:
377371
parser = argparse.ArgumentParser(formatter_class=NewlineHelpFormatter)
378372

379373
parser.set_defaults(colors=_supports_ansi_colors())
@@ -697,7 +691,7 @@ def parse_options(
697691

698692

699693
def process_ignore_words(
700-
words: Iterable[str], ignore_words: Set[str], ignore_words_cased: Set[str]
694+
words: Iterable[str], ignore_words: set[str], ignore_words_cased: set[str]
701695
) -> None:
702696
for word in words:
703697
word = word.strip()
@@ -708,10 +702,10 @@ def process_ignore_words(
708702

709703

710704
def parse_ignore_words_option(
711-
ignore_words_option: List[str],
712-
) -> Tuple[Set[str], Set[str]]:
713-
ignore_words: Set[str] = set()
714-
ignore_words_cased: Set[str] = set()
705+
ignore_words_option: list[str],
706+
) -> tuple[set[str], set[str]]:
707+
ignore_words: set[str] = set()
708+
ignore_words_cased: set[str] = set()
715709
if ignore_words_option:
716710
for comma_separated_words in ignore_words_option:
717711
process_ignore_words(
@@ -722,13 +716,13 @@ def parse_ignore_words_option(
722716
return (ignore_words, ignore_words_cased)
723717

724718

725-
def build_exclude_hashes(filename: str, exclude_lines: Set[str]) -> None:
719+
def build_exclude_hashes(filename: str, exclude_lines: set[str]) -> None:
726720
with open(filename, encoding="utf-8") as f:
727721
exclude_lines.update(line.rstrip() for line in f)
728722

729723

730724
def build_ignore_words(
731-
filename: str, ignore_words: Set[str], ignore_words_cased: Set[str]
725+
filename: str, ignore_words: set[str], ignore_words_cased: set[str]
732726
) -> None:
733727
with open(filename, encoding="utf-8") as f:
734728
process_ignore_words(
@@ -756,7 +750,7 @@ def ask_for_word_fix(
756750
misspelling: Misspelling,
757751
interactivity: int,
758752
colors: TermColors,
759-
) -> Tuple[bool, str]:
753+
) -> tuple[bool, str]:
760754
wrongword = match.group()
761755
if interactivity <= 0:
762756
return misspelling.fix, fix_case(wrongword, misspelling.data)
@@ -813,9 +807,9 @@ def ask_for_word_fix(
813807

814808

815809
def print_context(
816-
lines: List[str],
810+
lines: list[str],
817811
index: int,
818-
context: Tuple[int, int],
812+
context: tuple[int, int],
819813
) -> None:
820814
# context = (context_before, context_after)
821815
for i in range(index - context[0], index + context[1] + 1):
@@ -836,26 +830,26 @@ def extract_words(
836830
text: str,
837831
word_regex: Pattern[str],
838832
ignore_word_regex: Optional[Pattern[str]],
839-
) -> List[str]:
833+
) -> list[str]:
840834
return word_regex.findall(_ignore_word_sub(text, ignore_word_regex))
841835

842836

843837
def extract_words_iter(
844838
text: str,
845839
word_regex: Pattern[str],
846840
ignore_word_regex: Optional[Pattern[str]],
847-
) -> List[Match[str]]:
841+
) -> list[Match[str]]:
848842
return list(word_regex.finditer(_ignore_word_sub(text, ignore_word_regex)))
849843

850844

851845
def apply_uri_ignore_words(
852-
check_matches: List[Match[str]],
846+
check_matches: list[Match[str]],
853847
line: str,
854848
word_regex: Pattern[str],
855849
ignore_word_regex: Optional[Pattern[str]],
856850
uri_regex: Pattern[str],
857-
uri_ignore_words: Set[str],
858-
) -> List[Match[str]]:
851+
uri_ignore_words: set[str],
852+
) -> list[Match[str]]:
859853
if not uri_ignore_words:
860854
return check_matches
861855
for uri in uri_regex.findall(line):
@@ -873,15 +867,15 @@ def parse_file(
873867
filename: str,
874868
colors: TermColors,
875869
summary: Optional[Summary],
876-
misspellings: Dict[str, Misspelling],
877-
ignore_words_cased: Set[str],
878-
exclude_lines: Set[str],
870+
misspellings: dict[str, Misspelling],
871+
ignore_words_cased: set[str],
872+
exclude_lines: set[str],
879873
file_opener: FileOpener,
880874
word_regex: Pattern[str],
881875
ignore_word_regex: Optional[Pattern[str]],
882876
uri_regex: Pattern[str],
883-
uri_ignore_words: Set[str],
884-
context: Optional[Tuple[int, int]],
877+
uri_ignore_words: set[str],
878+
context: Optional[tuple[int, int]],
885879
options: argparse.Namespace,
886880
) -> int:
887881
bad_count = 0
@@ -1085,7 +1079,7 @@ def parse_file(
10851079

10861080
def flatten_clean_comma_separated_arguments(
10871081
arguments: Iterable[str],
1088-
) -> List[str]:
1082+
) -> list[str]:
10891083
"""
10901084
>>> flatten_clean_comma_separated_arguments(["a, b ,\n c, d,", "e"])
10911085
['a', 'b', 'c', 'd', 'e']
@@ -1227,7 +1221,7 @@ def main(*args: str) -> int:
12271221
f"ERROR: cannot find dictionary file: {dictionary}",
12281222
)
12291223
use_dictionaries.append(dictionary)
1230-
misspellings: Dict[str, Misspelling] = {}
1224+
misspellings: dict[str, Misspelling] = {}
12311225
for dictionary in use_dictionaries:
12321226
build_dict(dictionary, misspellings, ignore_words)
12331227
colors = TermColors()
@@ -1255,7 +1249,7 @@ def main(*args: str) -> int:
12551249
context_after = max(0, options.after_context)
12561250
context = (context_before, context_after)
12571251

1258-
exclude_lines: Set[str] = set()
1252+
exclude_lines: set[str] = set()
12591253
if options.exclude_file:
12601254
exclude_files = flatten_clean_comma_separated_arguments(options.exclude_file)
12611255
for exclude_file in exclude_files:

codespell_lib/_spellchecker.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
Copyright (C) 2011 ProFUSION embedded systems
1717
"""
1818

19-
from typing import (
20-
Dict,
21-
Set,
22-
)
23-
2419
# Pass all misspellings through this translation table to generate
2520
# alternative misspellings and fixes.
2621
alt_chars = (("'", "’"),) # noqa: RUF001
@@ -36,7 +31,7 @@ def __init__(self, data: str, fix: bool, reason: str) -> None:
3631
def add_misspelling(
3732
key: str,
3833
data: str,
39-
misspellings: Dict[str, Misspelling],
34+
misspellings: dict[str, Misspelling],
4035
) -> None:
4136
data = data.strip()
4237

@@ -53,8 +48,8 @@ def add_misspelling(
5348

5449
def build_dict(
5550
filename: str,
56-
misspellings: Dict[str, Misspelling],
57-
ignore_words: Set[str],
51+
misspellings: dict[str, Misspelling],
52+
ignore_words: set[str],
5853
) -> None:
5954
with open(filename, encoding="utf-8") as f:
6055
translate_tables = [(x, str.maketrans(x, y)) for x, y in alt_chars]

codespell_lib/tests/test_basic.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
import re
66
import subprocess
77
import sys
8+
from collections.abc import Generator
89
from io import StringIO
910
from pathlib import Path
1011
from shutil import copyfile
11-
from typing import Any, Generator, Optional, Tuple, Union
12+
from typing import Any, Optional, Union
1213
from unittest import mock
1314

1415
import pytest
@@ -39,7 +40,7 @@ def main(
3940
*args: Any,
4041
count: bool = True,
4142
std: bool = False,
42-
) -> Union[int, Tuple[int, str, str]]:
43+
) -> Union[int, tuple[int, str, str]]:
4344
args = tuple(str(arg) for arg in args)
4445
if count:
4546
args = ("--count", *args)
@@ -65,7 +66,7 @@ def main(
6566

6667

6768
def run_codespell(
68-
args: Tuple[Any, ...] = (),
69+
args: tuple[Any, ...] = (),
6970
cwd: Optional[Path] = None,
7071
) -> int:
7172
"""Run codespell."""
@@ -1373,7 +1374,7 @@ def FakeStdin(text: str) -> Generator[None, None, None]:
13731374

13741375
def run_codespell_stdin(
13751376
text: str,
1376-
args: Tuple[Any, ...],
1377+
args: tuple[Any, ...],
13771378
cwd: Optional[Path] = None,
13781379
) -> int:
13791380
"""Run codespell in stdin mode and return number of lines in output."""
@@ -1397,7 +1398,7 @@ def test_stdin(tmp_path: Path) -> None:
13971398
for _ in range(input_file_lines):
13981399
text += "abandonned\n"
13991400
for single_line_per_error in (True, False):
1400-
args: Tuple[str, ...] = ()
1401+
args: tuple[str, ...] = ()
14011402
if single_line_per_error:
14021403
args = ("--stdin-single-line",)
14031404
# we expect 'input_file_lines' number of lines with

codespell_lib/tests/test_dictionary.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import os.path as op
44
import pathlib
55
import re
6-
from typing import Any, Dict, Iterable, Optional, Set, Tuple
6+
from collections.abc import Iterable
7+
from typing import Any, Optional
78

89
import pytest
910

@@ -37,8 +38,8 @@
3738
)
3839
raise RuntimeError(msg) from e
3940

40-
global_err_dicts: Dict[str, Dict[str, Any]] = {}
41-
global_pairs: Set[Tuple[str, str]] = set()
41+
global_err_dicts: dict[str, dict[str, Any]] = {}
42+
global_pairs: set[tuple[str, str]] = set()
4243

4344
# Filename, should be seen as errors in aspell or not
4445
_data_dir = op.join(op.dirname(__file__), "..", "data")
@@ -61,8 +62,8 @@ def test_dictionaries_exist() -> None:
6162
@fname_params
6263
def test_dictionary_formatting(
6364
fname: str,
64-
in_aspell: Tuple[bool, bool],
65-
in_dictionary: Tuple[Iterable[str], Iterable[str]],
65+
in_aspell: tuple[bool, bool],
66+
in_dictionary: tuple[Iterable[str], Iterable[str]],
6667
) -> None:
6768
"""Test that all dictionary entries are valid."""
6869
errors = []
@@ -137,9 +138,9 @@ def _check_aspell(
137138
def _check_err_rep(
138139
err: str,
139140
rep: str,
140-
in_aspell: Tuple[Optional[bool], Optional[bool]],
141+
in_aspell: tuple[Optional[bool], Optional[bool]],
141142
fname: str,
142-
languages: Tuple[Iterable[str], Iterable[str]],
143+
languages: tuple[Iterable[str], Iterable[str]],
143144
) -> None:
144145
assert whitespace.search(err) is None, f"error {err!r} has whitespace"
145146
assert "," not in err, f"error {err!r} has a comma"
@@ -296,8 +297,8 @@ def test_error_checking_in_aspell(
296297
@pytest.mark.dependency(name="dictionary loop")
297298
def test_dictionary_looping(
298299
fname: str,
299-
in_aspell: Tuple[bool, bool],
300-
in_dictionary: Tuple[bool, bool],
300+
in_aspell: tuple[bool, bool],
301+
in_dictionary: tuple[bool, bool],
301302
) -> None:
302303
"""Test that all dictionary entries are valid."""
303304
this_err_dict = {}

0 commit comments

Comments
 (0)