175
175
)
176
176
177
177
rl_basic_quote_characters = ctypes .c_char_p .in_dll (readline_lib , "rl_basic_quote_characters" )
178
- orig_rl_basic_quotes = cast (" bytes" , ctypes .cast (rl_basic_quote_characters , ctypes .c_void_p ).value )
178
+ orig_rl_basic_quotes = cast (bytes , ctypes .cast (rl_basic_quote_characters , ctypes .c_void_p ).value )
179
179
180
180
181
181
class _SavedReadlineSettings :
@@ -707,7 +707,7 @@ def register_command_set(self, cmdset: CommandSet) -> None:
707
707
708
708
cmdset .on_register (self )
709
709
methods = cast (
710
- " list[tuple[str, Callable[..., Any]]]" ,
710
+ list [tuple [str , Callable [..., Any ]]],
711
711
inspect .getmembers (
712
712
cmdset ,
713
713
predicate = lambda meth : isinstance (meth , Callable ) # type: ignore[arg-type]
@@ -970,7 +970,7 @@ def find_subcommand(action: argparse.ArgumentParser, subcmd_names: list[str]) ->
970
970
971
971
target_parser = find_subcommand (command_parser , subcommand_names )
972
972
973
- subcmd_parser = cast (" argparse.ArgumentParser" , self ._build_parser (cmdset , subcmd_parser_builder ))
973
+ subcmd_parser = cast (argparse .ArgumentParser , self ._build_parser (cmdset , subcmd_parser_builder ))
974
974
from .decorators import (
975
975
_set_parser_prog ,
976
976
)
@@ -1153,7 +1153,7 @@ def allow_style_type(value: str) -> ansi.AllowStyle:
1153
1153
'Allow ANSI text style sequences in output (valid values: '
1154
1154
f'{ ansi .AllowStyle .ALWAYS } , { ansi .AllowStyle .NEVER } , { ansi .AllowStyle .TERMINAL } )' ,
1155
1155
self ,
1156
- choices_provider = cast (" ChoicesProviderFunc" , get_allow_style_choices ),
1156
+ choices_provider = cast (ChoicesProviderFunc , get_allow_style_choices ),
1157
1157
)
1158
1158
)
1159
1159
@@ -1945,7 +1945,7 @@ def _display_matches_gnu_readline(
1945
1945
1946
1946
# rl_display_match_list() expects matches to be in argv format where
1947
1947
# substitution is the first element, followed by the matches, and then a NULL.
1948
- strings_array = cast (" list[Optional[bytes]]" , (ctypes .c_char_p * (1 + len (encoded_matches ) + 1 ))())
1948
+ strings_array = cast (list [Optional [bytes ]], (ctypes .c_char_p * (1 + len (encoded_matches ) + 1 ))())
1949
1949
1950
1950
# Copy in the encoded strings and add a NULL to the end
1951
1951
strings_array [0 ] = encoded_substitution
@@ -2868,7 +2868,7 @@ def _redirect_output(self, statement: Statement) -> utils.RedirectionSavedState:
2868
2868
2869
2869
# Initialize the redirection saved state
2870
2870
redir_saved_state = utils .RedirectionSavedState (
2871
- cast (" TextIO" , self .stdout ), sys .stdout , self ._cur_pipe_proc_reader , self ._redirecting
2871
+ cast (TextIO , self .stdout ), sys .stdout , self ._cur_pipe_proc_reader , self ._redirecting
2872
2872
)
2873
2873
2874
2874
# The ProcReader for this command
@@ -2884,7 +2884,7 @@ def _redirect_output(self, statement: Statement) -> utils.RedirectionSavedState:
2884
2884
2885
2885
# Open each side of the pipe
2886
2886
subproc_stdin = open (read_fd )
2887
- new_stdout : TextIO = cast (" TextIO" , open (write_fd , 'w' ))
2887
+ new_stdout : TextIO = cast (TextIO , open (write_fd , 'w' ))
2888
2888
2889
2889
# Create pipe process in a separate group to isolate our signals from it. If a Ctrl-C event occurs,
2890
2890
# our sigint handler will forward it only to the most recent pipe process. This makes sure pipe
@@ -2925,7 +2925,7 @@ def _redirect_output(self, statement: Statement) -> utils.RedirectionSavedState:
2925
2925
new_stdout .close ()
2926
2926
raise RedirectionError (f'Pipe process exited with code { proc .returncode } before command could run' )
2927
2927
redir_saved_state .redirecting = True # type: ignore[unreachable]
2928
- cmd_pipe_proc_reader = utils .ProcReader (proc , cast (" TextIO" , self .stdout ), sys .stderr )
2928
+ cmd_pipe_proc_reader = utils .ProcReader (proc , cast (TextIO , self .stdout ), sys .stderr )
2929
2929
sys .stdout = self .stdout = new_stdout
2930
2930
2931
2931
elif statement .output :
@@ -2935,7 +2935,7 @@ def _redirect_output(self, statement: Statement) -> utils.RedirectionSavedState:
2935
2935
mode = 'a' if statement .output == constants .REDIRECTION_APPEND else 'w'
2936
2936
try :
2937
2937
# Use line buffering
2938
- new_stdout = cast (" TextIO" , open (utils .strip_quotes (statement .output_to ), mode = mode , buffering = 1 ))
2938
+ new_stdout = cast (TextIO , open (utils .strip_quotes (statement .output_to ), mode = mode , buffering = 1 ))
2939
2939
except OSError as ex :
2940
2940
raise RedirectionError (f'Failed to redirect because: { ex } ' )
2941
2941
@@ -2956,7 +2956,7 @@ def _redirect_output(self, statement: Statement) -> utils.RedirectionSavedState:
2956
2956
# no point opening up the temporary file
2957
2957
current_paste_buffer = get_paste_buffer ()
2958
2958
# create a temporary file to store output
2959
- new_stdout = cast (" TextIO" , tempfile .TemporaryFile (mode = "w+" ))
2959
+ new_stdout = cast (TextIO , tempfile .TemporaryFile (mode = "w+" ))
2960
2960
redir_saved_state .redirecting = True
2961
2961
sys .stdout = self .stdout = new_stdout
2962
2962
@@ -2989,8 +2989,8 @@ def _restore_output(self, statement: Statement, saved_redir_state: utils.Redirec
2989
2989
pass
2990
2990
2991
2991
# Restore the stdout values
2992
- self .stdout = cast (" TextIO" , saved_redir_state .saved_self_stdout )
2993
- sys .stdout = cast (" TextIO" , saved_redir_state .saved_sys_stdout )
2992
+ self .stdout = cast (TextIO , saved_redir_state .saved_self_stdout )
2993
+ sys .stdout = cast (TextIO , saved_redir_state .saved_sys_stdout )
2994
2994
2995
2995
# Check if we need to wait for the process being piped to
2996
2996
if self ._cur_pipe_proc_reader is not None :
@@ -3016,7 +3016,7 @@ def cmd_func(self, command: str) -> Optional[CommandFunc]:
3016
3016
"""
3017
3017
func_name = constants .COMMAND_FUNC_PREFIX + command
3018
3018
func = getattr (self , func_name , None )
3019
- return cast (" CommandFunc" , func ) if callable (func ) else None
3019
+ return cast (CommandFunc , func ) if callable (func ) else None
3020
3020
3021
3021
def onecmd (self , statement : Union [Statement , str ], * , add_to_history : bool = True ) -> bool :
3022
3022
"""This executes the actual do_* method for a command.
@@ -3276,7 +3276,7 @@ def _set_up_cmd2_readline(self) -> _SavedReadlineSettings:
3276
3276
# We don't want this behavior since cmd2 only adds a closing quote when self.allow_closing_quote is True.
3277
3277
# To fix this behavior, set readline's rl_basic_quote_characters to NULL. We don't need to worry about setting
3278
3278
# rl_completion_suppress_quote since we never declared rl_completer_quote_characters.
3279
- readline_settings .basic_quotes = cast (" bytes" , ctypes .cast (rl_basic_quote_characters , ctypes .c_void_p ).value )
3279
+ readline_settings .basic_quotes = cast (bytes , ctypes .cast (rl_basic_quote_characters , ctypes .c_void_p ).value )
3280
3280
rl_basic_quote_characters .value = None
3281
3281
3282
3282
readline_settings .completer = readline .get_completer ()
@@ -3941,7 +3941,7 @@ def _build_command_info(self) -> tuple[dict[str, list[str]], list[str], list[str
3941
3941
cmds_undoc : list [str ] = []
3942
3942
cmds_cats : dict [str , list [str ]] = {}
3943
3943
for command in visible_commands :
3944
- func = cast (" CommandFunc" , self .cmd_func (command ))
3944
+ func = cast (CommandFunc , self .cmd_func (command ))
3945
3945
has_help_func = False
3946
3946
has_parser = func in self ._command_parsers
3947
3947
@@ -4011,7 +4011,7 @@ def _print_topics(self, header: str, cmds: list[str], verbose: bool) -> None:
4011
4011
stdout_orig = self .stdout
4012
4012
try :
4013
4013
# redirect our internal stdout
4014
- self .stdout = cast (" TextIO" , result )
4014
+ self .stdout = cast (TextIO , result )
4015
4015
help_func ()
4016
4016
finally :
4017
4017
# restore internal stdout
@@ -4078,7 +4078,7 @@ def select(self, opts: Union[str, list[str], list[tuple[Any, Optional[str]]]], p
4078
4078
the text advertised to the user"""
4079
4079
local_opts : Union [list [str ], list [tuple [Any , Optional [str ]]]]
4080
4080
if isinstance (opts , str ):
4081
- local_opts = cast (" list[tuple[Any, Optional[str]]]" , list (zip (opts .split (), opts .split ())))
4081
+ local_opts = cast (list [tuple [Any , Optional [str ]]], list (zip (opts .split (), opts .split ())))
4082
4082
else :
4083
4083
local_opts = opts
4084
4084
fulloptions : list [tuple [Any , Optional [str ]]] = []
@@ -4278,7 +4278,7 @@ def do_shell(self, args: argparse.Namespace) -> None:
4278
4278
** kwargs ,
4279
4279
)
4280
4280
4281
- proc_reader = utils .ProcReader (proc , cast (" TextIO" , self .stdout ), sys .stderr ) # type: ignore[arg-type]
4281
+ proc_reader = utils .ProcReader (proc , cast (TextIO , self .stdout ), sys .stderr ) # type: ignore[arg-type]
4282
4282
proc_reader .wait ()
4283
4283
4284
4284
# Save the return code of the application for use in a pyscript
@@ -4337,7 +4337,7 @@ def _set_up_py_shell_env(self, interp: InteractiveConsole) -> _SavedCmd2Env:
4337
4337
# rlcompleter relies on the default settings of the Python readline module
4338
4338
if rl_type == RlType .GNU :
4339
4339
cmd2_env .readline_settings .basic_quotes = cast (
4340
- " bytes" , ctypes .cast (rl_basic_quote_characters , ctypes .c_void_p ).value
4340
+ bytes , ctypes .cast (rl_basic_quote_characters , ctypes .c_void_p ).value
4341
4341
)
4342
4342
rl_basic_quote_characters .value = orig_rl_basic_quotes
4343
4343
@@ -4986,8 +4986,8 @@ def _generate_transcript(
4986
4986
transcript += command
4987
4987
4988
4988
# Use a StdSim object to capture output
4989
- stdsim = utils .StdSim (cast (" TextIO" , self .stdout ))
4990
- self .stdout = cast (" TextIO" , stdsim )
4989
+ stdsim = utils .StdSim (cast (TextIO , self .stdout ))
4990
+ self .stdout = cast (TextIO , stdsim )
4991
4991
4992
4992
# then run the command and let the output go into our buffer
4993
4993
try :
@@ -5012,7 +5012,7 @@ def _generate_transcript(
5012
5012
with self .sigint_protection :
5013
5013
# Restore altered attributes to their original state
5014
5014
self .echo = saved_echo
5015
- self .stdout = cast (" TextIO" , saved_stdout )
5015
+ self .stdout = cast (TextIO , saved_stdout )
5016
5016
5017
5017
# Check if all commands ran
5018
5018
if commands_run < len (history ):
@@ -5226,7 +5226,7 @@ class TestMyAppCase(Cmd2TestCase):
5226
5226
setattr (self .__class__ , 'testfiles' , transcripts_expanded )
5227
5227
sys .argv = [sys .argv [0 ]] # the --test argument upsets unittest.main()
5228
5228
testcase = TestMyAppCase ()
5229
- stream = cast (" TextIO" , utils .StdSim (sys .stderr ))
5229
+ stream = cast (TextIO , utils .StdSim (sys .stderr ))
5230
5230
runner = unittest .TextTestRunner (stream = stream )
5231
5231
start_time = time .time ()
5232
5232
test_results = runner .run (testcase )
@@ -5615,7 +5615,7 @@ def register_postloop_hook(self, func: Callable[[], None]) -> None:
5615
5615
@classmethod
5616
5616
def _validate_postparsing_callable (cls , func : Callable [[plugin .PostparsingData ], plugin .PostparsingData ]) -> None :
5617
5617
"""Check parameter and return types for postparsing hooks"""
5618
- cls ._validate_callable_param_count (cast (" Callable[..., Any]" , func ), 1 )
5618
+ cls ._validate_callable_param_count (cast (Callable [..., Any ], func ), 1 )
5619
5619
signature = inspect .signature (func )
5620
5620
_ , param = list (signature .parameters .items ())[0 ]
5621
5621
if param .annotation != plugin .PostparsingData :
@@ -5637,7 +5637,7 @@ def _validate_prepostcmd_hook(
5637
5637
"""Check parameter and return types for pre and post command hooks."""
5638
5638
signature = inspect .signature (func )
5639
5639
# validate that the callable has the right number of parameters
5640
- cls ._validate_callable_param_count (cast (" Callable[..., Any]" , func ), 1 )
5640
+ cls ._validate_callable_param_count (cast (Callable [..., Any ], func ), 1 )
5641
5641
# validate the parameter has the right annotation
5642
5642
paramname = list (signature .parameters .keys ())[0 ]
5643
5643
param = signature .parameters [paramname ]
0 commit comments