2727import textwrap
2828from typing import (
2929 Any ,
30- Dict ,
3130 Iterable ,
32- List ,
3331 Match ,
3432 Optional ,
3533 Pattern ,
3634 Sequence ,
37- Set ,
3835 TextIO ,
39- Tuple ,
4036)
4137
4238if sys .platform == "win32" :
@@ -161,8 +157,8 @@ class QuietLevels:
161157
162158
163159class GlobMatch :
164- def __init__ (self , pattern : List [str ]) -> None :
165- self .pattern_list : List [str ] = pattern
160+ def __init__ (self , pattern : list [str ]) -> None :
161+ self .pattern_list : list [str ] = pattern
166162
167163 def match (self , filename : str ) -> bool :
168164 return any (fnmatch .fnmatch (filename , p ) for p in self .pattern_list )
@@ -184,7 +180,7 @@ def disable(self) -> None:
184180
185181class Summary :
186182 def __init__ (self ) -> None :
187- self .summary : Dict [str , int ] = {}
183+ self .summary : dict [str , int ] = {}
188184
189185 def update (self , wrongword : str ) -> None :
190186 if wrongword in self .summary :
@@ -227,12 +223,12 @@ def init_chardet(self) -> None:
227223
228224 self .encdetector = UniversalDetector ()
229225
230- def open (self , filename : str ) -> Tuple [ List [str ], str ]:
226+ def open (self , filename : str ) -> tuple [ list [str ], str ]:
231227 if self .use_chardet :
232228 return self .open_with_chardet (filename )
233229 return self .open_with_internal (filename )
234230
235- def open_with_chardet (self , filename : str ) -> Tuple [ List [str ], str ]:
231+ def open_with_chardet (self , filename : str ) -> tuple [ list [str ], str ]:
236232 self .encdetector .reset ()
237233 with open (filename , "rb" ) as fb :
238234 for line in fb :
@@ -259,7 +255,7 @@ def open_with_chardet(self, filename: str) -> Tuple[List[str], str]:
259255
260256 return lines , f .encoding
261257
262- def open_with_internal (self , filename : str ) -> Tuple [ List [str ], str ]:
258+ def open_with_internal (self , filename : str ) -> tuple [ list [str ], str ]:
263259 encoding = None
264260 first_try = True
265261 for encoding in ("utf-8" , "iso-8859-1" ):
@@ -286,7 +282,7 @@ def open_with_internal(self, filename: str) -> Tuple[List[str], str]:
286282
287283 return lines , encoding
288284
289- def get_lines (self , f : TextIO ) -> List [str ]:
285+ def get_lines (self , f : TextIO ) -> list [str ]:
290286 if self .ignore_multiline_regex :
291287 text = f .read ()
292288 pos = 0
@@ -313,7 +309,7 @@ def get_lines(self, f: TextIO) -> List[str]:
313309class NewlineHelpFormatter (argparse .HelpFormatter ):
314310 """Help formatter that preserves newlines and deals with lists."""
315311
316- def _split_lines (self , text : str , width : int ) -> List [str ]:
312+ def _split_lines (self , text : str , width : int ) -> list [str ]:
317313 parts = text .split ("\n " )
318314 out = []
319315 for part in parts :
@@ -330,7 +326,7 @@ def _split_lines(self, text: str, width: int) -> List[str]:
330326 return out
331327
332328
333- def _toml_to_parseconfig (toml_dict : Dict [str , Any ]) -> Dict [str , Any ]:
329+ def _toml_to_parseconfig (toml_dict : dict [str , Any ]) -> dict [str , Any ]:
334330 """Convert a dict read from a TOML file to the parseconfig.read_dict() format."""
335331 return {
336332 k : "" if v is True else "," .join (v ) if isinstance (v , list ) else v
@@ -373,7 +369,7 @@ def _supports_ansi_colors() -> bool:
373369
374370def parse_options (
375371 args : Sequence [str ],
376- ) -> Tuple [argparse .Namespace , argparse .ArgumentParser , List [str ]]:
372+ ) -> tuple [argparse .Namespace , argparse .ArgumentParser , list [str ]]:
377373 parser = argparse .ArgumentParser (formatter_class = NewlineHelpFormatter )
378374
379375 parser .set_defaults (colors = _supports_ansi_colors ())
@@ -697,7 +693,7 @@ def parse_options(
697693
698694
699695def process_ignore_words (
700- words : Iterable [str ], ignore_words : Set [str ], ignore_words_cased : Set [str ]
696+ words : Iterable [str ], ignore_words : set [str ], ignore_words_cased : set [str ]
701697) -> None :
702698 for word in words :
703699 word = word .strip ()
@@ -708,10 +704,10 @@ def process_ignore_words(
708704
709705
710706def 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 ()
707+ ignore_words_option : list [str ],
708+ ) -> tuple [ set [str ], set [str ]]:
709+ ignore_words : set [str ] = set ()
710+ ignore_words_cased : set [str ] = set ()
715711 if ignore_words_option :
716712 for comma_separated_words in ignore_words_option :
717713 process_ignore_words (
@@ -722,13 +718,13 @@ def parse_ignore_words_option(
722718 return (ignore_words , ignore_words_cased )
723719
724720
725- def build_exclude_hashes (filename : str , exclude_lines : Set [str ]) -> None :
721+ def build_exclude_hashes (filename : str , exclude_lines : set [str ]) -> None :
726722 with open (filename , encoding = "utf-8" ) as f :
727723 exclude_lines .update (line .rstrip () for line in f )
728724
729725
730726def build_ignore_words (
731- filename : str , ignore_words : Set [str ], ignore_words_cased : Set [str ]
727+ filename : str , ignore_words : set [str ], ignore_words_cased : set [str ]
732728) -> None :
733729 with open (filename , encoding = "utf-8" ) as f :
734730 process_ignore_words (
@@ -756,7 +752,7 @@ def ask_for_word_fix(
756752 misspelling : Misspelling ,
757753 interactivity : int ,
758754 colors : TermColors ,
759- ) -> Tuple [bool , str ]:
755+ ) -> tuple [bool , str ]:
760756 wrongword = match .group ()
761757 if interactivity <= 0 :
762758 return misspelling .fix , fix_case (wrongword , misspelling .data )
@@ -813,9 +809,9 @@ def ask_for_word_fix(
813809
814810
815811def print_context (
816- lines : List [str ],
812+ lines : list [str ],
817813 index : int ,
818- context : Tuple [int , int ],
814+ context : tuple [int , int ],
819815) -> None :
820816 # context = (context_before, context_after)
821817 for i in range (index - context [0 ], index + context [1 ] + 1 ):
@@ -836,26 +832,26 @@ def extract_words(
836832 text : str ,
837833 word_regex : Pattern [str ],
838834 ignore_word_regex : Optional [Pattern [str ]],
839- ) -> List [str ]:
835+ ) -> list [str ]:
840836 return word_regex .findall (_ignore_word_sub (text , ignore_word_regex ))
841837
842838
843839def extract_words_iter (
844840 text : str ,
845841 word_regex : Pattern [str ],
846842 ignore_word_regex : Optional [Pattern [str ]],
847- ) -> List [Match [str ]]:
843+ ) -> list [Match [str ]]:
848844 return list (word_regex .finditer (_ignore_word_sub (text , ignore_word_regex )))
849845
850846
851847def apply_uri_ignore_words (
852- check_matches : List [Match [str ]],
848+ check_matches : list [Match [str ]],
853849 line : str ,
854850 word_regex : Pattern [str ],
855851 ignore_word_regex : Optional [Pattern [str ]],
856852 uri_regex : Pattern [str ],
857- uri_ignore_words : Set [str ],
858- ) -> List [Match [str ]]:
853+ uri_ignore_words : set [str ],
854+ ) -> list [Match [str ]]:
859855 if not uri_ignore_words :
860856 return check_matches
861857 for uri in uri_regex .findall (line ):
@@ -873,15 +869,15 @@ def parse_file(
873869 filename : str ,
874870 colors : TermColors ,
875871 summary : Optional [Summary ],
876- misspellings : Dict [str , Misspelling ],
877- ignore_words_cased : Set [str ],
878- exclude_lines : Set [str ],
872+ misspellings : dict [str , Misspelling ],
873+ ignore_words_cased : set [str ],
874+ exclude_lines : set [str ],
879875 file_opener : FileOpener ,
880876 word_regex : Pattern [str ],
881877 ignore_word_regex : Optional [Pattern [str ]],
882878 uri_regex : Pattern [str ],
883- uri_ignore_words : Set [str ],
884- context : Optional [Tuple [int , int ]],
879+ uri_ignore_words : set [str ],
880+ context : Optional [tuple [int , int ]],
885881 options : argparse .Namespace ,
886882) -> int :
887883 bad_count = 0
@@ -1085,7 +1081,7 @@ def parse_file(
10851081
10861082def flatten_clean_comma_separated_arguments (
10871083 arguments : Iterable [str ],
1088- ) -> List [str ]:
1084+ ) -> list [str ]:
10891085 """
10901086 >>> flatten_clean_comma_separated_arguments(["a, b ,\n c, d,", "e"])
10911087 ['a', 'b', 'c', 'd', 'e']
@@ -1227,7 +1223,7 @@ def main(*args: str) -> int:
12271223 f"ERROR: cannot find dictionary file: { dictionary } " ,
12281224 )
12291225 use_dictionaries .append (dictionary )
1230- misspellings : Dict [str , Misspelling ] = {}
1226+ misspellings : dict [str , Misspelling ] = {}
12311227 for dictionary in use_dictionaries :
12321228 build_dict (dictionary , misspellings , ignore_words )
12331229 colors = TermColors ()
@@ -1255,7 +1251,7 @@ def main(*args: str) -> int:
12551251 context_after = max (0 , options .after_context )
12561252 context = (context_before , context_after )
12571253
1258- exclude_lines : Set [str ] = set ()
1254+ exclude_lines : set [str ] = set ()
12591255 if options .exclude_file :
12601256 exclude_files = flatten_clean_comma_separated_arguments (options .exclude_file )
12611257 for exclude_file in exclude_files :
0 commit comments