2121import random
2222import subprocess
2323import sys
24- from typing import Any , Callable , Dict , IO , List , Optional , Tuple , Union , Final
24+ from typing import Any , IO , Final
25+ from collections .abc import Callable
2526
2627from fixtures import Fixture
2728
@@ -35,23 +36,23 @@ class _Unpassed:
3536_unpassed : Final = _Unpassed ()
3637
3738
38- class FakeProcess ( object ) :
39+ class FakeProcess :
3940 """A test double process, roughly meeting subprocess.Popen's contract."""
4041
41- def __init__ (self , args : Dict [str , Any ], info : Dict [str , Any ]) -> None :
42+ def __init__ (self , args : dict [str , Any ], info : dict [str , Any ]) -> None :
4243 self ._args = args
4344 self .stdin : Any = info .get ("stdin" )
4445 self .stdout : Any = info .get ("stdout" )
4546 self .stderr : Any = info .get ("stderr" )
4647 self .pid : int = random .randint (0 , 65536 )
4748 self ._returncode : int = info .get ("returncode" , 0 )
48- self .returncode : Optional [ int ] = None
49+ self .returncode : int | None = None
4950
5051 @property
5152 def args (self ) -> Any :
5253 return self ._args ["args" ]
5354
54- def poll (self ) -> Optional [ int ] :
55+ def poll (self ) -> int | None :
5556 """Get the current value of FakeProcess.returncode.
5657
5758 The returncode is None before communicate() and/or wait() are called,
@@ -61,8 +62,8 @@ def poll(self) -> Optional[int]:
6162 return self .returncode
6263
6364 def communicate (
64- self , input : Optional [ Union [ bytes , str ]] = None , timeout : Optional [ float ] = None
65- ) -> Tuple [Any , Any ]:
65+ self , input : bytes | str | None = None , timeout : float | None = None
66+ ) -> tuple [Any , Any ]:
6667 self .returncode = self ._returncode
6768 if self .stdin and input :
6869 self .stdin .write (input )
@@ -86,8 +87,8 @@ def kill(self) -> None:
8687 pass
8788
8889 def wait (
89- self , timeout : Optional [ float ] = None , endtime : Optional [ float ] = None
90- ) -> Optional [ int ] :
90+ self , timeout : float | None = None , endtime : float | None = None
91+ ) -> int | None :
9192 if self .returncode is None :
9293 self .communicate ()
9394 return self .returncode
@@ -103,7 +104,7 @@ class FakePopen(Fixture):
103104 """
104105
105106 def __init__ (
106- self , get_info : Callable [[Dict [str , Any ]], Dict [str , Any ]] = lambda _ : {}
107+ self , get_info : Callable [[dict [str , Any ]], dict [str , Any ]] = lambda _ : {}
107108 ) -> None :
108109 """Create a PopenFixture
109110
@@ -127,45 +128,45 @@ def get_info(proc_args):
127128 get_info is not supplied or doesn't return a dict with an explicit
128129 'returncode' key).
129130 """
130- super (FakePopen , self ).__init__ ()
131+ super ().__init__ ()
131132 self .get_info = get_info
132133
133134 def _setUp (self ) -> None :
134135 self .addCleanup (setattr , subprocess , "Popen" , subprocess .Popen )
135136 subprocess .Popen = self # type: ignore[assignment,misc]
136- self .procs : List [FakeProcess ] = []
137+ self .procs : list [FakeProcess ] = []
137138
138139 # The method has the correct signature so we error appropriately if called
139140 # wrongly.
140141 def __call__ (
141142 self ,
142- args : Union [ str , List [str ] ],
143- bufsize : Union [ int , _Unpassed ] = _unpassed ,
144- executable : Union [ str , None , _Unpassed ] = _unpassed ,
145- stdin : Union [ None , int , IO [Any ], _Unpassed ] = _unpassed ,
146- stdout : Union [ None , int , IO [Any ], _Unpassed ] = _unpassed ,
147- stderr : Union [ None , int , IO [Any ], _Unpassed ] = _unpassed ,
148- preexec_fn : Union [ Callable [[], None ], None , _Unpassed ] = _unpassed ,
149- close_fds : Union [ bool , _Unpassed ] = _unpassed ,
150- shell : Union [ bool , _Unpassed ] = _unpassed ,
151- cwd : Union [ str , None , _Unpassed ] = _unpassed ,
152- env : Union [ Dict [ str , str ], None , _Unpassed ] = _unpassed ,
153- universal_newlines : Union [ bool , _Unpassed ] = _unpassed ,
154- startupinfo : Union [ Any , _Unpassed ] = _unpassed ,
155- creationflags : Union [ int , _Unpassed ] = _unpassed ,
156- restore_signals : Union [ bool , _Unpassed ] = _unpassed ,
157- start_new_session : Union [ bool , _Unpassed ] = _unpassed ,
158- pass_fds : Union [ Any , _Unpassed ] = _unpassed ,
143+ args : str | list [str ],
144+ bufsize : int | _Unpassed = _unpassed ,
145+ executable : str | None | _Unpassed = _unpassed ,
146+ stdin : None | int | IO [Any ] | _Unpassed = _unpassed ,
147+ stdout : None | int | IO [Any ] | _Unpassed = _unpassed ,
148+ stderr : None | int | IO [Any ] | _Unpassed = _unpassed ,
149+ preexec_fn : Callable [[], None ] | None | _Unpassed = _unpassed ,
150+ close_fds : bool | _Unpassed = _unpassed ,
151+ shell : bool | _Unpassed = _unpassed ,
152+ cwd : str | None | _Unpassed = _unpassed ,
153+ env : dict [ str , str ] | None | _Unpassed = _unpassed ,
154+ universal_newlines : bool | _Unpassed = _unpassed ,
155+ startupinfo : Any | _Unpassed = _unpassed ,
156+ creationflags : int | _Unpassed = _unpassed ,
157+ restore_signals : bool | _Unpassed = _unpassed ,
158+ start_new_session : bool | _Unpassed = _unpassed ,
159+ pass_fds : Any | _Unpassed = _unpassed ,
159160 * ,
160- group : Union [ str , int , None , _Unpassed ] = _unpassed ,
161- extra_groups : Union [ List [ Union [ str , int ]], None , _Unpassed ] = _unpassed ,
162- user : Union [ str , int , None , _Unpassed ] = _unpassed ,
163- umask : Union [ int , None , _Unpassed ] = _unpassed ,
164- encoding : Union [ str , None , _Unpassed ] = _unpassed ,
165- errors : Union [ str , None , _Unpassed ] = _unpassed ,
166- text : Union [ bool , None , _Unpassed ] = _unpassed ,
167- pipesize : Union [ int , _Unpassed ] = _unpassed ,
168- process_group : Union [ int , None , _Unpassed ] = _unpassed ,
161+ group : str | int | None | _Unpassed = _unpassed ,
162+ extra_groups : list [ str | int ] | None | _Unpassed = _unpassed ,
163+ user : str | int | None | _Unpassed = _unpassed ,
164+ umask : int | None | _Unpassed = _unpassed ,
165+ encoding : str | None | _Unpassed = _unpassed ,
166+ errors : str | None | _Unpassed = _unpassed ,
167+ text : bool | None | _Unpassed = _unpassed ,
168+ pipesize : int | _Unpassed = _unpassed ,
169+ process_group : int | None | _Unpassed = _unpassed ,
169170 ) -> FakeProcess :
170171 if sys .version_info < (3 , 11 ) and not isinstance (process_group , _Unpassed ):
171172 raise TypeError (
0 commit comments