2525import re
2626import sys
2727import textwrap
28+ from collections .abc import Iterable , Sequence
29+ from re import Match , Pattern
2830from 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
4236if sys .platform == "win32" :
@@ -161,8 +155,8 @@ class QuietLevels:
161155
162156
163157class 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
185179class 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]:
313307class 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
374368def 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
699693def 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
710704def 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
730724def 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
815809def 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
843837def 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
851845def 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
10861080def 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 :
0 commit comments