Skip to content

Commit ef6ba80

Browse files
authored
Remove unused mypy ignores. (#1361)
1 parent aa95d05 commit ef6ba80

File tree

10 files changed

+36
-36
lines changed

10 files changed

+36
-36
lines changed

.github/workflows/mypy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ jobs:
1919
# Only a single commit is fetched by default, for the ref/SHA that triggered the workflow.
2020
# Set fetch-depth: 0 to fetch all history for all branches and tags.
2121
fetch-depth: 0 # Needed for setuptools_scm to work correctly
22-
- run: pip install -U --user pip mypy rich rich-argparse
22+
- run: pip install -U --user pip mypy pyperclip rich rich-argparse wcwidth
2323
- run: mypy .

cmd2/ansi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
cast,
1818
)
1919

20-
from wcwidth import ( # type: ignore[import]
20+
from wcwidth import ( # type: ignore[import-untyped]
2121
wcswidth,
2222
)
2323

cmd2/argparse_completer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def _format_completions(self, arg_state: _ArgumentState, completions: Union[List
557557
if not self._cmd2_app.matches_sorted:
558558
# If all orig_value types are numbers, then sort by that value
559559
if all_nums:
560-
completion_items.sort(key=lambda c: c.orig_value) # type: ignore[no-any-return]
560+
completion_items.sort(key=lambda c: c.orig_value)
561561

562562
# Otherwise sort as strings
563563
else:
@@ -744,12 +744,12 @@ def _complete_arg(
744744
if not arg_choices.is_completer:
745745
choices_func = arg_choices.choices_provider
746746
if isinstance(choices_func, ChoicesProviderFuncWithTokens):
747-
completion_items = choices_func(*args, **kwargs) # type: ignore[arg-type]
747+
completion_items = choices_func(*args, **kwargs)
748748
else: # pragma: no cover
749749
# This won't hit because runtime checking doesn't check function argument types and will always
750750
# resolve true above. Mypy, however, does see the difference and gives an error that can't be
751751
# ignored. Mypy issue #5485 discusses this problem
752-
completion_items = choices_func(*args) # type: ignore[arg-type]
752+
completion_items = choices_func(*args)
753753
# else case is already covered above
754754
else:
755755
completion_items = arg_choices

cmd2/argparse_custom.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -807,19 +807,19 @@ def _add_argument_wrapper(
807807
# Validate nargs tuple
808808
if (
809809
len(nargs) != 2
810-
or not isinstance(nargs[0], int) # type: ignore[unreachable]
811-
or not (isinstance(nargs[1], int) or nargs[1] == constants.INFINITY) # type: ignore[misc]
810+
or not isinstance(nargs[0], int)
811+
or not (isinstance(nargs[1], int) or nargs[1] == constants.INFINITY)
812812
):
813813
raise ValueError('Ranged values for nargs must be a tuple of 1 or 2 integers')
814-
if nargs[0] >= nargs[1]: # type: ignore[misc]
814+
if nargs[0] >= nargs[1]:
815815
raise ValueError('Invalid nargs range. The first value must be less than the second')
816816
if nargs[0] < 0:
817817
raise ValueError('Negative numbers are invalid for nargs range')
818818

819819
# Save the nargs tuple as our range setting
820820
nargs_range = nargs
821821
range_min = nargs_range[0]
822-
range_max = nargs_range[1] # type: ignore[misc]
822+
range_max = nargs_range[1]
823823

824824
# Convert nargs into a format argparse recognizes
825825
if range_min == 0:
@@ -858,7 +858,7 @@ def _add_argument_wrapper(
858858
new_arg = orig_actions_container_add_argument(self, *args, **kwargs)
859859

860860
# Set the custom attributes
861-
new_arg.set_nargs_range(nargs_range) # type: ignore[arg-type, attr-defined]
861+
new_arg.set_nargs_range(nargs_range) # type: ignore[attr-defined]
862862

863863
if choices_provider:
864864
new_arg.set_choices_provider(choices_provider) # type: ignore[attr-defined]
@@ -894,7 +894,7 @@ def _get_nargs_pattern_wrapper(self: argparse.ArgumentParser, action: argparse.A
894894
if nargs_range[1] == constants.INFINITY:
895895
range_max = ''
896896
else:
897-
range_max = nargs_range[1] # type: ignore[assignment]
897+
range_max = nargs_range[1]
898898

899899
nargs_pattern = f'(-*A{{{nargs_range[0]},{range_max}}}-*)'
900900

@@ -1429,10 +1429,10 @@ def format_help(self) -> str:
14291429
formatter = self._get_formatter()
14301430

14311431
# usage
1432-
formatter.add_usage(self.usage, self._actions, self._mutually_exclusive_groups) # type: ignore[arg-type]
1432+
formatter.add_usage(self.usage, self._actions, self._mutually_exclusive_groups)
14331433

14341434
# description
1435-
formatter.add_text(self.description) # type: ignore[arg-type]
1435+
formatter.add_text(self.description)
14361436

14371437
# Begin cmd2 customization (separate required and optional arguments)
14381438

@@ -1473,7 +1473,7 @@ def format_help(self) -> str:
14731473
# End cmd2 customization
14741474

14751475
# epilog
1476-
formatter.add_text(self.epilog) # type: ignore[arg-type]
1476+
formatter.add_text(self.epilog)
14771477

14781478
# determine help from format above
14791479
return formatter.format_help() + '\n'

cmd2/clipboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import typing
77

8-
import pyperclip # type: ignore[import]
8+
import pyperclip # type: ignore[import-untyped]
99

1010

1111
def get_paste_buffer() -> str:

cmd2/cmd2.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ def _unregister_subcommands(self, cmdset: Union[CommandSet, 'Cmd']) -> None:
987987

988988
for action in command_parser._actions:
989989
if isinstance(action, argparse._SubParsersAction):
990-
action.remove_parser(subcommand_name) # type: ignore[arg-type,attr-defined]
990+
action.remove_parser(subcommand_name) # type: ignore[attr-defined]
991991
break
992992

993993
@property
@@ -2095,15 +2095,15 @@ def _perform_completion(
20952095
completer.complete, tokens=raw_tokens[1:] if preserve_quotes else tokens[1:], cmd_set=cmd_set
20962096
)
20972097
else:
2098-
completer_func = self.completedefault # type: ignore[assignment]
2098+
completer_func = self.completedefault
20992099

21002100
# Not a recognized command
21012101
else:
21022102
# Check if this command should be run as a shell command
21032103
if self.default_to_shell and command in utils.get_exes_in_path(command):
21042104
completer_func = self.path_complete
21052105
else:
2106-
completer_func = self.completedefault # type: ignore[assignment]
2106+
completer_func = self.completedefault
21072107

21082108
# Otherwise we are completing the command token or performing custom completion
21092109
else:
@@ -2805,11 +2805,11 @@ def _redirect_output(self, statement: Statement) -> utils.RedirectionSavedState:
28052805
kwargs['executable'] = shell
28062806

28072807
# For any stream that is a StdSim, we will use a pipe so we can capture its output
2808-
proc = subprocess.Popen( # type: ignore[call-overload]
2808+
proc = subprocess.Popen(
28092809
statement.pipe_to,
28102810
stdin=subproc_stdin,
28112811
stdout=subprocess.PIPE if isinstance(self.stdout, utils.StdSim) else self.stdout, # type: ignore[unreachable]
2812-
stderr=subprocess.PIPE if isinstance(sys.stderr, utils.StdSim) else sys.stderr, # type: ignore[unreachable]
2812+
stderr=subprocess.PIPE if isinstance(sys.stderr, utils.StdSim) else sys.stderr,
28132813
shell=True,
28142814
**kwargs,
28152815
)
@@ -2829,7 +2829,7 @@ def _redirect_output(self, statement: Statement) -> utils.RedirectionSavedState:
28292829
new_stdout.close()
28302830
raise RedirectionError(f'Pipe process exited with code {proc.returncode} before command could run')
28312831
else:
2832-
redir_saved_state.redirecting = True # type: ignore[unreachable]
2832+
redir_saved_state.redirecting = True
28332833
cmd_pipe_proc_reader = utils.ProcReader(proc, cast(TextIO, self.stdout), sys.stderr)
28342834
sys.stdout = self.stdout = new_stdout
28352835

@@ -3068,7 +3068,7 @@ def complete_none(text: str, state: int) -> Optional[str]: # pragma: no cover
30683068
parser.add_argument(
30693069
'arg',
30703070
suppress_tab_hint=True,
3071-
choices=choices, # type: ignore[arg-type]
3071+
choices=choices,
30723072
choices_provider=choices_provider,
30733073
completer=completer,
30743074
)
@@ -3846,7 +3846,7 @@ def complete_set_value(
38463846
arg_name,
38473847
metavar=arg_name,
38483848
help=settable.description,
3849-
choices=settable.choices, # type: ignore[arg-type]
3849+
choices=settable.choices,
38503850
choices_provider=settable.choices_provider,
38513851
completer=settable.completer,
38523852
)
@@ -4001,15 +4001,15 @@ def do_shell(self, args: argparse.Namespace) -> None:
40014001
# still receive the SIGINT since it is in the same process group as us.
40024002
with self.sigint_protection:
40034003
# For any stream that is a StdSim, we will use a pipe so we can capture its output
4004-
proc = subprocess.Popen( # type: ignore[call-overload]
4004+
proc = subprocess.Popen(
40054005
expanded_command,
40064006
stdout=subprocess.PIPE if isinstance(self.stdout, utils.StdSim) else self.stdout, # type: ignore[unreachable]
4007-
stderr=subprocess.PIPE if isinstance(sys.stderr, utils.StdSim) else sys.stderr, # type: ignore[unreachable]
4007+
stderr=subprocess.PIPE if isinstance(sys.stderr, utils.StdSim) else sys.stderr,
40084008
shell=True,
40094009
**kwargs,
40104010
)
40114011

4012-
proc_reader = utils.ProcReader(proc, cast(TextIO, self.stdout), sys.stderr) # type: ignore[arg-type]
4012+
proc_reader = utils.ProcReader(proc, cast(TextIO, self.stdout), sys.stderr)
40134013
proc_reader.wait()
40144014

40154015
# Save the return code of the application for use in a pyscript
@@ -4101,10 +4101,10 @@ def _set_up_py_shell_env(self, interp: InteractiveConsole) -> _SavedCmd2Env:
41014101
self._reset_py_display()
41024102

41034103
cmd2_env.sys_stdout = sys.stdout
4104-
sys.stdout = self.stdout # type: ignore[assignment]
4104+
sys.stdout = self.stdout
41054105

41064106
cmd2_env.sys_stdin = sys.stdin
4107-
sys.stdin = self.stdin # type: ignore[assignment]
4107+
sys.stdin = self.stdin
41084108

41094109
return cmd2_env
41104110

@@ -4114,8 +4114,8 @@ def _restore_cmd2_env(self, cmd2_env: _SavedCmd2Env) -> None:
41144114
41154115
:param cmd2_env: the environment settings to restore
41164116
"""
4117-
sys.stdout = cmd2_env.sys_stdout # type: ignore[assignment]
4118-
sys.stdin = cmd2_env.sys_stdin # type: ignore[assignment]
4117+
sys.stdout = cmd2_env.sys_stdout
4118+
sys.stdin = cmd2_env.sys_stdin
41194119

41204120
# Set up readline for cmd2
41214121
if rl_type != RlType.NONE:

cmd2/decorators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def cmd_wrapper(*args: Any, **kwargs: Any) -> Optional[bool]:
184184
cmd2_app, statement = _parse_positionals(args)
185185
_, parsed_arglist = cmd2_app.statement_parser.get_command_arg_list(command_name, statement, preserve_quotes)
186186
args_list = _arg_swap(args, statement, parsed_arglist)
187-
return func(*args_list, **kwargs) # type: ignore[call-arg]
187+
return func(*args_list, **kwargs)
188188

189189
command_name = func.__name__[len(constants.COMMAND_FUNC_PREFIX) :]
190190
cmd_wrapper.__doc__ = func.__doc__
@@ -383,7 +383,7 @@ def cmd_wrapper(*args: Any, **kwargs: Dict[str, Any]) -> Optional[bool]:
383383
delattr(ns, constants.NS_ATTR_SUBCMD_HANDLER)
384384

385385
args_list = _arg_swap(args, statement_arg, *new_args)
386-
return func(*args_list, **kwargs) # type: ignore[call-arg]
386+
return func(*args_list, **kwargs)
387387

388388
command_name = func.__name__[len(constants.COMMAND_FUNC_PREFIX) :]
389389

cmd2/parsing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def shlex_split(str_to_split: str) -> List[str]:
3939

4040

4141
@dataclass(frozen=True)
42-
class Statement(str): # type: ignore[override]
42+
class Statement(str):
4343
"""String subclass with additional attributes to store the results of parsing.
4444
4545
The ``cmd`` module in the standard library passes commands around as a

cmd2/table_creator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
Union,
2525
)
2626

27-
from wcwidth import ( # type: ignore[import]
27+
from wcwidth import ( # type: ignore[import-untyped]
2828
wcwidth,
2929
)
3030

cmd2/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ def categorize(func: Union[Callable[..., Any], Iterable[Callable[..., Any]]], ca
11721172
setattr(item, constants.CMD_ATTR_HELP_CATEGORY, category)
11731173
else:
11741174
if inspect.ismethod(func):
1175-
setattr(func.__func__, constants.CMD_ATTR_HELP_CATEGORY, category) # type: ignore[attr-defined]
1175+
setattr(func.__func__, constants.CMD_ATTR_HELP_CATEGORY, category)
11761176
else:
11771177
setattr(func, constants.CMD_ATTR_HELP_CATEGORY, category)
11781178

@@ -1192,7 +1192,7 @@ def get_defining_class(meth: Callable[..., Any]) -> Optional[Type[Any]]:
11921192
if inspect.ismethod(meth) or (
11931193
inspect.isbuiltin(meth) and getattr(meth, '__self__') is not None and getattr(meth.__self__, '__class__')
11941194
):
1195-
for cls in inspect.getmro(meth.__self__.__class__): # type: ignore[attr-defined]
1195+
for cls in inspect.getmro(meth.__self__.__class__):
11961196
if meth.__name__ in cls.__dict__:
11971197
return cls
11981198
meth = getattr(meth, '__func__', meth) # fallback to __qualname__ parsing

0 commit comments

Comments
 (0)