55import shutil
66import sys
77from argparse import ArgumentParser , Namespace
8+ from collections .abc import Sequence
89from enum import IntEnum
910from itertools import chain
1011from logging import LogRecord
1112from pathlib import Path
1213from textwrap import indent
13- from typing import Any , Dict , List , NoReturn , Optional , Sequence , Text , Tuple , Union
14+ from typing import Any , NoReturn
1415
1516from tempren .exceptions import FileNotSupportedError , TemplateEvaluationError
1617from tempren .filesystem import DestinationAlreadyExistsError
@@ -87,7 +88,7 @@ def tag_name_from_executable(exec_path: Path) -> str:
8788 return base_name
8889
8990
90- def adhoc_tag (val : str ) -> Tuple [TagName , Path ]:
91+ def adhoc_tag (val : str ) -> tuple [TagName , Path ]:
9192 val = nonempty_string (val )
9293 components = val .split ("=" , maxsplit = 1 )
9394 if len (components ) == 1 :
@@ -109,7 +110,7 @@ def adhoc_tag(val: str) -> Tuple[TagName, Path]:
109110 raise argparse .ArgumentTypeError (f"'{ tag_name } ' cannot be used as tag name" )
110111
111112
112- def alias (val : str ) -> Tuple [TagName , str ]:
113+ def alias (val : str ) -> tuple [TagName , str ]:
113114 val = nonempty_string (val )
114115 components = val .split ("=" , maxsplit = 1 )
115116 if len (components ) < 2 :
@@ -126,8 +127,8 @@ def alias(val: str) -> Tuple[TagName, str]:
126127
127128
128129def validate_adhoc_tags (
129- adhoc_tags : List [ List [ Tuple [TagName , Path ]]]
130- ) -> Dict [TagName , Path ]:
130+ adhoc_tags : list [ list [ tuple [TagName , Path ]]]
131+ ) -> dict [TagName , Path ]:
131132 if not adhoc_tags :
132133 return dict ()
133134 list_of_tuples = list (chain (* adhoc_tags ))
@@ -152,7 +153,7 @@ def validate_adhoc_tags(
152153 return dict (list_of_tuples )
153154
154155
155- def validate_aliases (aliases : List [ List [ Tuple [TagName , str ]]]) -> Dict [TagName , str ]:
156+ def validate_aliases (aliases : list [ list [ tuple [TagName , str ]]]) -> dict [TagName , str ]:
156157 # TODO: Merge with validate_adhoc_tags
157158 if not aliases :
158159 return dict ()
@@ -182,7 +183,7 @@ def validate_aliases(aliases: List[List[Tuple[TagName, str]]]) -> Dict[TagName,
182183class SystemExitError (Exception ): # TODO: Use ConfigurationError instead
183184 status : int
184185
185- def __init__ (self , status : int , message : Optional [ str ] ):
186+ def __init__ (self , status : int , message : str | None ):
186187 super ().__init__ (message )
187188 self .status = status
188189
@@ -192,8 +193,8 @@ def __call__(
192193 self ,
193194 parser : ArgumentParser ,
194195 args : Namespace ,
195- values : Union [ Text , Sequence [Any ], None ] ,
196- option_string : Optional [ Text ] = None ,
196+ values : str | Sequence [Any ] | None ,
197+ option_string : str | None = None ,
197198 ):
198199 registry = build_tag_registry (
199200 validate_adhoc_tags (args .ad_hoc ), validate_aliases (args .alias )
@@ -227,8 +228,8 @@ def __call__(
227228 self ,
228229 parser : ArgumentParser ,
229230 args : Namespace ,
230- values : Union [ str , Sequence [Any ], None ] ,
231- option_string : Optional [ Text ] = None ,
231+ values : str | Sequence [Any ] | None ,
232+ option_string : str | None = None ,
232233 ):
233234 if values is None :
234235 parser .print_help ()
@@ -268,8 +269,8 @@ def __call__(
268269 self ,
269270 parser : ArgumentParser ,
270271 namespace : Namespace ,
271- values : Union [ Text , Sequence [Any ], None ] ,
272- option_string : Optional [ Text ] = None ,
272+ values : str | Sequence [Any ] | None ,
273+ option_string : str | None = None ,
273274 ):
274275 log .info (self .find_package_version ())
275276 parser .exit ()
@@ -290,8 +291,8 @@ def __call__(
290291 self ,
291292 parser : ArgumentParser ,
292293 namespace : Namespace ,
293- values : Union [ Text , Sequence [Any ], None ] ,
294- option_string : Optional [ Text ] = None ,
294+ values : str | Sequence [Any ] | None ,
295+ option_string : str | None = None ,
295296 ):
296297 root_logger = logging .getLogger ()
297298 root_logger .setLevel (root_logger .level - 10 )
@@ -303,8 +304,8 @@ def __call__(
303304 self ,
304305 parser : ArgumentParser ,
305306 namespace : Namespace ,
306- values : Union [ Text , Sequence [Any ], None ] ,
307- option_string : Optional [ Text ] = None ,
307+ values : str | Sequence [Any ] | None ,
308+ option_string : str | None = None ,
308309 ):
309310 root_logger = logging .getLogger ()
310311 root_logger .setLevel (root_logger .level + 10 )
@@ -320,7 +321,7 @@ def _get_help_string(self, action):
320321 return action .help
321322
322323
323- def process_cli_configuration (argv : List [str ]) -> RuntimeConfiguration :
324+ def process_cli_configuration (argv : list [str ]) -> RuntimeConfiguration :
324325 log .debug ("Parsing command line arguments" )
325326 parser = argparse .ArgumentParser (
326327 prog = "tempren" ,
@@ -520,7 +521,7 @@ def process_cli_configuration(argv: List[str]) -> RuntimeConfiguration:
520521 # We could catch resulting `SystemExit` exception but related error message still would be missing.
521522 # This behaviour is not comfortable for testing so here we monkeypatch exit method to
522523 # throw more practical exception instead.
523- def throwing_exit (status : int = 0 , message : Optional [ str ] = "" ) -> NoReturn :
524+ def throwing_exit (status : int = 0 , message : str | None = "" ) -> NoReturn :
524525 raise SystemExitError (status , message )
525526
526527 parser .exit = throwing_exit # type: ignore
@@ -602,7 +603,7 @@ def render_template_evaluation_error(
602603
603604def cli_prompt_conflict_resolver (
604605 source_path : Path , destination_path : Path
605- ) -> Union [ ConflictResolutionStrategy , Path ] :
606+ ) -> ConflictResolutionStrategy | Path :
606607 log .warning ("While processing:" )
607608 log .warning (f" { source_path } " )
608609 log .warning ("following path was generated:" )
0 commit comments