2727 Any ,
2828 Callable ,
2929 Dict ,
30- Iterable ,
31- Iterator ,
3230 List ,
33- Mapping ,
34- MutableMapping ,
3531 Optional ,
3632 Tuple ,
3733 Union ,
3834 cast ,
3935 no_type_check ,
4036)
37+ from collections .abc import Iterable , Iterator , Mapping , MutableMapping
4138
4239from .escseqparse import parse , remove_ansi
4340from .termformatconstants import (
6764}
6865
6966
70- class FrozenAttributes (Dict [str , Union [int , bool ]]):
67+ class FrozenAttributes (dict [str , Union [int , bool ]]):
7168 """Immutable dictionary class for format string attributes"""
7269
7370 def __setitem__ (self , key : str , value : Union [int , bool ]) -> None :
@@ -215,7 +212,7 @@ def reinit(self, chunk: Chunk) -> None:
215212 divides .append (divides [- 1 ] + wcwidth (c ))
216213 self .divides = divides
217214
218- def request (self , max_width : int ) -> Optional [Tuple [int , Chunk ]]:
215+ def request (self , max_width : int ) -> Optional [tuple [int , Chunk ]]:
219216 """Requests a sub-chunk of max_width or shorter. Returns None if no chunks left."""
220217 if max_width < 1 :
221218 raise ValueError ("requires positive integer max_width" )
@@ -413,8 +410,8 @@ def copy_with_new_atts(self, **attributes: Union[bool, int]) -> "FmtStr":
413410
414411 def join (self , iterable : Iterable [Union [str , "FmtStr" ]]) -> "FmtStr" :
415412 """Joins an iterable yielding strings or FmtStrs with self as separator"""
416- before : List [Chunk ] = []
417- chunks : List [Chunk ] = []
413+ before : list [Chunk ] = []
414+ chunks : list [Chunk ] = []
418415 for s in iterable :
419416 chunks .extend (before )
420417 before = self .chunks
@@ -432,7 +429,7 @@ def split(
432429 sep : Optional [str ] = None ,
433430 maxsplit : Optional [int ] = None ,
434431 regex : bool = False ,
435- ) -> List ["FmtStr" ]:
432+ ) -> list ["FmtStr" ]:
436433 """Split based on separator, optionally using a regex.
437434
438435 Capture groups are ignored in regex, the whole pattern is matched
@@ -453,7 +450,7 @@ def split(
453450 )
454451 ]
455452
456- def splitlines (self , keepends : bool = False ) -> List ["FmtStr" ]:
453+ def splitlines (self , keepends : bool = False ) -> list ["FmtStr" ]:
457454 """Return a list of lines, split on newline characters,
458455 include line boundaries, if keepends is true."""
459456 lines = self .split ("\n " )
@@ -560,7 +557,7 @@ def __mul__(self, other: int) -> "FmtStr":
560557 # TODO ensure empty FmtStr isn't a problem
561558
562559 @property
563- def shared_atts (self ) -> Dict [str , Union [int , bool ]]:
560+ def shared_atts (self ) -> dict [str , Union [int , bool ]]:
564561 """Gets atts shared among all nonzero length component Chunks"""
565562 # TODO cache this, could get ugly for large FmtStrs
566563 atts = {}
@@ -582,7 +579,7 @@ def new_with_atts_removed(self, *attributes: str) -> "FmtStr":
582579 return result
583580
584581 @no_type_check
585- def __getattr__ (self , att ):
582+ def __getattr__ (self , att : str ):
586583 # thanks to @aerenchyma/@jczett
587584 if not hasattr (self .s , att ):
588585 raise AttributeError (f"No attribute { att !r} " )
@@ -600,7 +597,7 @@ def func_help(*args, **kwargs):
600597 return func_help
601598
602599 @property
603- def divides (self ) -> List [int ]:
600+ def divides (self ) -> list [int ]:
604601 """List of indices of divisions between the constituent chunks."""
605602 acc = [0 ]
606603 for s in self .chunks :
@@ -752,7 +749,7 @@ def width_aware_slice(s: str, start: int, end: int, replacement_char: str = " ")
752749 return "" .join (new_chunk_chars )
753750
754751
755- def linesplit (string : Union [str , FmtStr ], columns : int ) -> List [FmtStr ]:
752+ def linesplit (string : Union [str , FmtStr ], columns : int ) -> list [FmtStr ]:
756753 """Returns a list of lines, split on the last possible space of each line.
757754
758755 Split spaces will be removed. Whitespaces will be normalized to one space.
@@ -820,9 +817,9 @@ def normalize_slice(length: int, index: Union[int, slice]) -> slice:
820817
821818
822819def parse_args (
823- args : Tuple [str , ...],
820+ args : tuple [str , ...],
824821 kwargs : MutableMapping [str , Union [int , bool , str ]],
825- ) -> Mapping [str , Union [int , bool ]]:
822+ ) -> MutableMapping [str , Union [int , bool ]]:
826823 """Returns a kwargs dictionary by turning args into kwargs"""
827824 if "style" in kwargs :
828825 args += (cast (str , kwargs ["style" ]),)
0 commit comments