183
183
)
184
184
185
185
rl_basic_quote_characters = ctypes .c_char_p .in_dll (readline_lib , "rl_basic_quote_characters" )
186
- orig_rl_basic_quotes = cast (bytes , ctypes .cast (rl_basic_quote_characters , ctypes .c_void_p ).value )
186
+ orig_rl_basic_quotes = cast (" bytes" , ctypes .cast (rl_basic_quote_characters , ctypes .c_void_p ).value )
187
187
188
188
189
189
class _SavedReadlineSettings :
@@ -715,7 +715,7 @@ def register_command_set(self, cmdset: CommandSet) -> None:
715
715
716
716
cmdset .on_register (self )
717
717
methods = cast (
718
- List [Tuple [str , Callable [..., Any ]]],
718
+ " List[Tuple[str, Callable[..., Any]]]" ,
719
719
inspect .getmembers (
720
720
cmdset ,
721
721
predicate = lambda meth : isinstance (meth , Callable ) # type: ignore[arg-type]
@@ -978,7 +978,7 @@ def find_subcommand(action: argparse.ArgumentParser, subcmd_names: List[str]) ->
978
978
979
979
target_parser = find_subcommand (command_parser , subcommand_names )
980
980
981
- subcmd_parser = cast (argparse .ArgumentParser , self ._build_parser (cmdset , subcmd_parser_builder ))
981
+ subcmd_parser = cast (" argparse.ArgumentParser" , self ._build_parser (cmdset , subcmd_parser_builder ))
982
982
from .decorators import (
983
983
_set_parser_prog ,
984
984
)
@@ -1161,7 +1161,7 @@ def allow_style_type(value: str) -> ansi.AllowStyle:
1161
1161
'Allow ANSI text style sequences in output (valid values: '
1162
1162
f'{ ansi .AllowStyle .ALWAYS } , { ansi .AllowStyle .NEVER } , { ansi .AllowStyle .TERMINAL } )' ,
1163
1163
self ,
1164
- choices_provider = cast (ChoicesProviderFunc , get_allow_style_choices ),
1164
+ choices_provider = cast (" ChoicesProviderFunc" , get_allow_style_choices ),
1165
1165
)
1166
1166
)
1167
1167
@@ -1953,7 +1953,7 @@ def _display_matches_gnu_readline(
1953
1953
1954
1954
# rl_display_match_list() expects matches to be in argv format where
1955
1955
# substitution is the first element, followed by the matches, and then a NULL.
1956
- strings_array = cast (List [Optional [bytes ]], (ctypes .c_char_p * (1 + len (encoded_matches ) + 1 ))())
1956
+ strings_array = cast (" List[Optional[bytes]]" , (ctypes .c_char_p * (1 + len (encoded_matches ) + 1 ))())
1957
1957
1958
1958
# Copy in the encoded strings and add a NULL to the end
1959
1959
strings_array [0 ] = encoded_substitution
@@ -2877,7 +2877,7 @@ def _redirect_output(self, statement: Statement) -> utils.RedirectionSavedState:
2877
2877
2878
2878
# Initialize the redirection saved state
2879
2879
redir_saved_state = utils .RedirectionSavedState (
2880
- cast (TextIO , self .stdout ), sys .stdout , self ._cur_pipe_proc_reader , self ._redirecting
2880
+ cast (" TextIO" , self .stdout ), sys .stdout , self ._cur_pipe_proc_reader , self ._redirecting
2881
2881
)
2882
2882
2883
2883
# The ProcReader for this command
@@ -2893,7 +2893,7 @@ def _redirect_output(self, statement: Statement) -> utils.RedirectionSavedState:
2893
2893
2894
2894
# Open each side of the pipe
2895
2895
subproc_stdin = io .open (read_fd , 'r' )
2896
- new_stdout : TextIO = cast (TextIO , io .open (write_fd , 'w' ))
2896
+ new_stdout : TextIO = cast (" TextIO" , io .open (write_fd , 'w' ))
2897
2897
2898
2898
# Create pipe process in a separate group to isolate our signals from it. If a Ctrl-C event occurs,
2899
2899
# our sigint handler will forward it only to the most recent pipe process. This makes sure pipe
@@ -2934,7 +2934,7 @@ def _redirect_output(self, statement: Statement) -> utils.RedirectionSavedState:
2934
2934
new_stdout .close ()
2935
2935
raise RedirectionError (f'Pipe process exited with code { proc .returncode } before command could run' )
2936
2936
redir_saved_state .redirecting = True # type: ignore[unreachable]
2937
- cmd_pipe_proc_reader = utils .ProcReader (proc , cast (TextIO , self .stdout ), sys .stderr )
2937
+ cmd_pipe_proc_reader = utils .ProcReader (proc , cast (" TextIO" , self .stdout ), sys .stderr )
2938
2938
sys .stdout = self .stdout = new_stdout
2939
2939
2940
2940
elif statement .output :
@@ -2944,7 +2944,7 @@ def _redirect_output(self, statement: Statement) -> utils.RedirectionSavedState:
2944
2944
mode = 'a' if statement .output == constants .REDIRECTION_APPEND else 'w'
2945
2945
try :
2946
2946
# Use line buffering
2947
- new_stdout = cast (TextIO , open (utils .strip_quotes (statement .output_to ), mode = mode , buffering = 1 ))
2947
+ new_stdout = cast (" TextIO" , open (utils .strip_quotes (statement .output_to ), mode = mode , buffering = 1 ))
2948
2948
except OSError as ex :
2949
2949
raise RedirectionError (f'Failed to redirect because: { ex } ' )
2950
2950
@@ -2965,7 +2965,7 @@ def _redirect_output(self, statement: Statement) -> utils.RedirectionSavedState:
2965
2965
# no point opening up the temporary file
2966
2966
current_paste_buffer = get_paste_buffer ()
2967
2967
# create a temporary file to store output
2968
- new_stdout = cast (TextIO , tempfile .TemporaryFile (mode = "w+" ))
2968
+ new_stdout = cast (" TextIO" , tempfile .TemporaryFile (mode = "w+" ))
2969
2969
redir_saved_state .redirecting = True
2970
2970
sys .stdout = self .stdout = new_stdout
2971
2971
@@ -2998,8 +2998,8 @@ def _restore_output(self, statement: Statement, saved_redir_state: utils.Redirec
2998
2998
pass
2999
2999
3000
3000
# Restore the stdout values
3001
- self .stdout = cast (TextIO , saved_redir_state .saved_self_stdout )
3002
- sys .stdout = cast (TextIO , saved_redir_state .saved_sys_stdout )
3001
+ self .stdout = cast (" TextIO" , saved_redir_state .saved_self_stdout )
3002
+ sys .stdout = cast (" TextIO" , saved_redir_state .saved_sys_stdout )
3003
3003
3004
3004
# Check if we need to wait for the process being piped to
3005
3005
if self ._cur_pipe_proc_reader is not None :
@@ -3025,7 +3025,7 @@ def cmd_func(self, command: str) -> Optional[CommandFunc]:
3025
3025
"""
3026
3026
func_name = constants .COMMAND_FUNC_PREFIX + command
3027
3027
func = getattr (self , func_name , None )
3028
- return cast (CommandFunc , func ) if callable (func ) else None
3028
+ return cast (" CommandFunc" , func ) if callable (func ) else None
3029
3029
3030
3030
def onecmd (self , statement : Union [Statement , str ], * , add_to_history : bool = True ) -> bool :
3031
3031
"""This executes the actual do_* method for a command.
@@ -3285,7 +3285,7 @@ def _set_up_cmd2_readline(self) -> _SavedReadlineSettings:
3285
3285
# We don't want this behavior since cmd2 only adds a closing quote when self.allow_closing_quote is True.
3286
3286
# To fix this behavior, set readline's rl_basic_quote_characters to NULL. We don't need to worry about setting
3287
3287
# rl_completion_suppress_quote since we never declared rl_completer_quote_characters.
3288
- readline_settings .basic_quotes = cast (bytes , ctypes .cast (rl_basic_quote_characters , ctypes .c_void_p ).value )
3288
+ readline_settings .basic_quotes = cast (" bytes" , ctypes .cast (rl_basic_quote_characters , ctypes .c_void_p ).value )
3289
3289
rl_basic_quote_characters .value = None
3290
3290
3291
3291
readline_settings .completer = readline .get_completer ()
@@ -3950,7 +3950,7 @@ def _build_command_info(self) -> Tuple[Dict[str, List[str]], List[str], List[str
3950
3950
cmds_undoc : List [str ] = []
3951
3951
cmds_cats : Dict [str , List [str ]] = {}
3952
3952
for command in visible_commands :
3953
- func = cast (CommandFunc , self .cmd_func (command ))
3953
+ func = cast (" CommandFunc" , self .cmd_func (command ))
3954
3954
has_help_func = False
3955
3955
has_parser = func in self ._command_parsers
3956
3956
@@ -4020,7 +4020,7 @@ def _print_topics(self, header: str, cmds: List[str], verbose: bool) -> None:
4020
4020
stdout_orig = self .stdout
4021
4021
try :
4022
4022
# redirect our internal stdout
4023
- self .stdout = cast (TextIO , result )
4023
+ self .stdout = cast (" TextIO" , result )
4024
4024
help_func ()
4025
4025
finally :
4026
4026
# restore internal stdout
@@ -4087,7 +4087,7 @@ def select(self, opts: Union[str, List[str], List[Tuple[Any, Optional[str]]]], p
4087
4087
the text advertised to the user"""
4088
4088
local_opts : Union [List [str ], List [Tuple [Any , Optional [str ]]]]
4089
4089
if isinstance (opts , str ):
4090
- local_opts = cast (List [Tuple [Any , Optional [str ]]], list (zip (opts .split (), opts .split ())))
4090
+ local_opts = cast (" List[Tuple[Any, Optional[str]]]" , list (zip (opts .split (), opts .split ())))
4091
4091
else :
4092
4092
local_opts = opts
4093
4093
fulloptions : List [Tuple [Any , Optional [str ]]] = []
@@ -4287,7 +4287,7 @@ def do_shell(self, args: argparse.Namespace) -> None:
4287
4287
** kwargs ,
4288
4288
)
4289
4289
4290
- proc_reader = utils .ProcReader (proc , cast (TextIO , self .stdout ), sys .stderr ) # type: ignore[arg-type]
4290
+ proc_reader = utils .ProcReader (proc , cast (" TextIO" , self .stdout ), sys .stderr ) # type: ignore[arg-type]
4291
4291
proc_reader .wait ()
4292
4292
4293
4293
# Save the return code of the application for use in a pyscript
@@ -4346,7 +4346,7 @@ def _set_up_py_shell_env(self, interp: InteractiveConsole) -> _SavedCmd2Env:
4346
4346
# rlcompleter relies on the default settings of the Python readline module
4347
4347
if rl_type == RlType .GNU :
4348
4348
cmd2_env .readline_settings .basic_quotes = cast (
4349
- bytes , ctypes .cast (rl_basic_quote_characters , ctypes .c_void_p ).value
4349
+ " bytes" , ctypes .cast (rl_basic_quote_characters , ctypes .c_void_p ).value
4350
4350
)
4351
4351
rl_basic_quote_characters .value = orig_rl_basic_quotes
4352
4352
@@ -4995,8 +4995,8 @@ def _generate_transcript(
4995
4995
transcript += command
4996
4996
4997
4997
# Use a StdSim object to capture output
4998
- stdsim = utils .StdSim (cast (TextIO , self .stdout ))
4999
- self .stdout = cast (TextIO , stdsim )
4998
+ stdsim = utils .StdSim (cast (" TextIO" , self .stdout ))
4999
+ self .stdout = cast (" TextIO" , stdsim )
5000
5000
5001
5001
# then run the command and let the output go into our buffer
5002
5002
try :
@@ -5021,7 +5021,7 @@ def _generate_transcript(
5021
5021
with self .sigint_protection :
5022
5022
# Restore altered attributes to their original state
5023
5023
self .echo = saved_echo
5024
- self .stdout = cast (TextIO , saved_stdout )
5024
+ self .stdout = cast (" TextIO" , saved_stdout )
5025
5025
5026
5026
# Check if all commands ran
5027
5027
if commands_run < len (history ):
@@ -5235,7 +5235,7 @@ class TestMyAppCase(Cmd2TestCase):
5235
5235
setattr (self .__class__ , 'testfiles' , transcripts_expanded )
5236
5236
sys .argv = [sys .argv [0 ]] # the --test argument upsets unittest.main()
5237
5237
testcase = TestMyAppCase ()
5238
- stream = cast (TextIO , utils .StdSim (sys .stderr ))
5238
+ stream = cast (" TextIO" , utils .StdSim (sys .stderr ))
5239
5239
runner = unittest .TextTestRunner (stream = stream )
5240
5240
start_time = time .time ()
5241
5241
test_results = runner .run (testcase )
@@ -5624,7 +5624,7 @@ def register_postloop_hook(self, func: Callable[[], None]) -> None:
5624
5624
@classmethod
5625
5625
def _validate_postparsing_callable (cls , func : Callable [[plugin .PostparsingData ], plugin .PostparsingData ]) -> None :
5626
5626
"""Check parameter and return types for postparsing hooks"""
5627
- cls ._validate_callable_param_count (cast (Callable [..., Any ], func ), 1 )
5627
+ cls ._validate_callable_param_count (cast (" Callable[..., Any]" , func ), 1 )
5628
5628
signature = inspect .signature (func )
5629
5629
_ , param = list (signature .parameters .items ())[0 ]
5630
5630
if param .annotation != plugin .PostparsingData :
@@ -5646,7 +5646,7 @@ def _validate_prepostcmd_hook(
5646
5646
"""Check parameter and return types for pre and post command hooks."""
5647
5647
signature = inspect .signature (func )
5648
5648
# validate that the callable has the right number of parameters
5649
- cls ._validate_callable_param_count (cast (Callable [..., Any ], func ), 1 )
5649
+ cls ._validate_callable_param_count (cast (" Callable[..., Any]" , func ), 1 )
5650
5650
# validate the parameter has the right annotation
5651
5651
paramname = list (signature .parameters .keys ())[0 ]
5652
5652
param = signature .parameters [paramname ]
0 commit comments