1414import logging
1515import subprocess
1616import sys
17+ import typing as t
1718from collections .abc import Iterable , Mapping , MutableMapping , Sequence
18- from typing import IO , TYPE_CHECKING , Any , AnyStr , Callable , Optional , Protocol , Union
1919
2020from libvcs import exc
2121from libvcs ._internal .types import StrOrBytesPath
@@ -35,7 +35,7 @@ def console_to_str(s: bytes) -> str:
3535 return str (s )
3636
3737
38- if TYPE_CHECKING :
38+ if t . TYPE_CHECKING :
3939 _LoggerAdapter = logging .LoggerAdapter [logging .Logger ]
4040 from typing_extensions import TypeAlias
4141else :
@@ -58,7 +58,9 @@ class CmdLoggingAdapter(_LoggerAdapter):
5858 directory basename, name of repo, hint, etc. e.g. 'django'
5959 """
6060
61- def __init__ (self , bin_name : str , keyword : str , * args : Any , ** kwargs : Any ) -> None :
61+ def __init__ (
62+ self , bin_name : str , keyword : str , * args : t .Any , ** kwargs : t .Any
63+ ) -> None :
6264 #: bin_name
6365 self .bin_name = bin_name
6466 #: directory basename, name of repository, hint, etc.
@@ -69,8 +71,8 @@ def __init__(self, bin_name: str, keyword: str, *args: Any, **kwargs: Any) -> No
6971 def process (
7072 self ,
7173 msg : str ,
72- kwargs : MutableMapping [str , Any ],
73- ) -> tuple [Any , MutableMapping [str , Any ]]:
74+ kwargs : MutableMapping [str , t . Any ],
75+ ) -> tuple [t . Any , MutableMapping [str , t . Any ]]:
7476 """Add additional context information for loggers."""
7577 prefixed_dict = {}
7678 prefixed_dict ["bin_name" ] = self .bin_name
@@ -81,24 +83,24 @@ def process(
8183 return msg , kwargs
8284
8385
84- class ProgressCallbackProtocol (Protocol ):
86+ class ProgressCallbackProtocol (t . Protocol ):
8587 """Callback to report subprocess communication."""
8688
87- def __call__ (self , output : AnyStr , timestamp : datetime .datetime ) -> None :
89+ def __call__ (self , output : t . AnyStr , timestamp : datetime .datetime ) -> None :
8890 """Process progress for subprocess communication."""
8991 ...
9092
9193
9294if sys .platform == "win32" :
9395 _ENV : TypeAlias = Mapping [str , str ]
9496else :
95- _ENV : TypeAlias = Union [
97+ _ENV : TypeAlias = t . Union [
9698 Mapping [bytes , StrOrBytesPath ],
9799 Mapping [str , StrOrBytesPath ],
98100 ]
99101
100- _CMD = Union [StrOrBytesPath , Sequence [StrOrBytesPath ]]
101- _FILE : TypeAlias = Optional [Union [int , IO [Any ]]]
102+ _CMD = t . Union [StrOrBytesPath , Sequence [StrOrBytesPath ]]
103+ _FILE : TypeAlias = t . Optional [t . Union [int , t . IO [t . Any ]]]
102104
103105
104106def run (
@@ -108,17 +110,17 @@ def run(
108110 stdin : _FILE | None = None ,
109111 stdout : _FILE | None = None ,
110112 stderr : _FILE | None = None ,
111- preexec_fn : Callable [[], Any ] | None = None ,
113+ preexec_fn : t . Callable [[], t . Any ] | None = None ,
112114 close_fds : bool = True ,
113115 shell : bool = False ,
114116 cwd : StrOrBytesPath | None = None ,
115117 env : _ENV | None = None ,
116118 universal_newlines : bool = False ,
117- startupinfo : Any | None = None ,
119+ startupinfo : t . Any | None = None ,
118120 creationflags : int = 0 ,
119121 restore_signals : bool = True ,
120122 start_new_session : bool = False ,
121- pass_fds : Any = (),
123+ pass_fds : t . Any = (),
122124 * ,
123125 text : bool | None = None ,
124126 encoding : str | None = None ,
@@ -205,7 +207,7 @@ def progress_cb(output, timestamp):
205207 line = None
206208 if log_in_real_time and callback is None :
207209
208- def progress_cb (output : AnyStr , timestamp : datetime .datetime ) -> None :
210+ def progress_cb (output : t . AnyStr , timestamp : datetime .datetime ) -> None :
209211 sys .stdout .write (str (output ))
210212 sys .stdout .flush ()
211213
0 commit comments