Skip to content

Commit

Permalink
Removed 'noinspection' comments since they are PyCharm-specific.
Browse files Browse the repository at this point in the history
  • Loading branch information
kmvanbrunt committed Sep 16, 2024
1 parent b82117c commit 8ee89ee
Show file tree
Hide file tree
Showing 16 changed files with 4 additions and 91 deletions.
1 change: 0 additions & 1 deletion cmd2/ansi.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ class BgColor(AnsiSequence):
####################################################################################
# Implementations intended for direct use
####################################################################################
# noinspection PyPep8Naming
class Cursor:
"""Create ANSI sequences to alter the cursor position"""

Expand Down
4 changes: 0 additions & 4 deletions cmd2/argparse_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
ARG_TOKENS = 'arg_tokens'


# noinspection PyProtectedMember
def _build_hint(parser: argparse.ArgumentParser, arg_action: argparse.Action) -> str:
"""Build tab completion hint for a given argument"""
# Check if hinting is disabled for this argument
Expand All @@ -82,7 +81,6 @@ def _single_prefix_char(token: str, parser: argparse.ArgumentParser) -> bool:
return len(token) == 1 and token[0] in parser.prefix_chars


# noinspection PyProtectedMember
def _looks_like_flag(token: str, parser: argparse.ArgumentParser) -> bool:
"""
Determine if a token looks like a flag. Unless an argument has nargs set to argparse.REMAINDER,
Expand Down Expand Up @@ -144,7 +142,6 @@ def __init__(self, arg_action: argparse.Action) -> None:
self.max = self.action.nargs


# noinspection PyProtectedMember
class _UnfinishedFlagError(CompletionError):
def __init__(self, flag_arg_state: _ArgumentState) -> None:
"""
Expand All @@ -171,7 +168,6 @@ def __init__(self, parser: argparse.ArgumentParser, arg_action: argparse.Action)
super().__init__(_build_hint(parser, arg_action), apply_style=False)


# noinspection PyProtectedMember
class ArgparseCompleter:
"""Automatic command line tab completion based on argparse parameters"""

Expand Down
26 changes: 0 additions & 26 deletions cmd2/argparse_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,6 @@ def my_completer(self, text, line, begidx, endidx, arg_tokens)
import argparse
import re
import sys

# noinspection PyUnresolvedReferences,PyProtectedMember
from argparse import (
ONE_OR_MORE,
ZERO_OR_MORE,
Expand Down Expand Up @@ -307,7 +305,6 @@ class CompletionItem(str):
def __new__(cls, value: object, *args: Any, **kwargs: Any) -> 'CompletionItem':
return super(CompletionItem, cls).__new__(cls, value)

# noinspection PyUnusedLocal
def __init__(self, value: object, description: str = '', *args: Any) -> None:
"""
CompletionItem Initializer
Expand Down Expand Up @@ -731,11 +728,9 @@ def _action_set_custom_parameter(self: argparse.Action, value: Any) -> None:


# Save original _ActionsContainer.add_argument so we can call it in our wrapper
# noinspection PyProtectedMember
orig_actions_container_add_argument = argparse._ActionsContainer.add_argument


# noinspection PyProtectedMember
def _add_argument_wrapper(
self: argparse._ActionsContainer,
*args: Any,
Expand Down Expand Up @@ -870,19 +865,16 @@ def _add_argument_wrapper(


# Overwrite _ActionsContainer.add_argument with our wrapper
# noinspection PyProtectedMember
setattr(argparse._ActionsContainer, 'add_argument', _add_argument_wrapper)

############################################################################################################
# Patch ArgumentParser._get_nargs_pattern with our wrapper to support nargs ranges
############################################################################################################

# Save original ArgumentParser._get_nargs_pattern so we can call it in our wrapper
# noinspection PyProtectedMember
orig_argument_parser_get_nargs_pattern = argparse.ArgumentParser._get_nargs_pattern


# noinspection PyProtectedMember
def _get_nargs_pattern_wrapper(self: argparse.ArgumentParser, action: argparse.Action) -> str:
# Wrapper around ArgumentParser._get_nargs_pattern behavior to support nargs ranges
nargs_range = action.get_nargs_range() # type: ignore[attr-defined]
Expand All @@ -904,18 +896,15 @@ def _get_nargs_pattern_wrapper(self: argparse.ArgumentParser, action: argparse.A


# Overwrite ArgumentParser._get_nargs_pattern with our wrapper
# noinspection PyProtectedMember
setattr(argparse.ArgumentParser, '_get_nargs_pattern', _get_nargs_pattern_wrapper)


############################################################################################################
# Patch ArgumentParser._match_argument with our wrapper to support nargs ranges
############################################################################################################
# noinspection PyProtectedMember
orig_argument_parser_match_argument = argparse.ArgumentParser._match_argument


# noinspection PyProtectedMember
def _match_argument_wrapper(self: argparse.ArgumentParser, action: argparse.Action, arg_strings_pattern: str) -> int:
# Wrapper around ArgumentParser._match_argument behavior to support nargs ranges
nargs_pattern = self._get_nargs_pattern(action)
Expand All @@ -931,7 +920,6 @@ def _match_argument_wrapper(self: argparse.ArgumentParser, action: argparse.Acti


# Overwrite ArgumentParser._match_argument with our wrapper
# noinspection PyProtectedMember
setattr(argparse.ArgumentParser, '_match_argument', _match_argument_wrapper)


Expand All @@ -945,7 +933,6 @@ def _match_argument_wrapper(self: argparse.ArgumentParser, action: argparse.Acti
ATTR_AP_COMPLETER_TYPE = 'ap_completer_type'


# noinspection PyPep8Naming
def _ArgumentParser_get_ap_completer_type(self: argparse.ArgumentParser) -> Optional[Type['ArgparseCompleter']]:
"""
Get the ap_completer_type attribute of an argparse ArgumentParser.
Expand All @@ -963,7 +950,6 @@ def _ArgumentParser_get_ap_completer_type(self: argparse.ArgumentParser) -> Opti
setattr(argparse.ArgumentParser, 'get_ap_completer_type', _ArgumentParser_get_ap_completer_type)


# noinspection PyPep8Naming
def _ArgumentParser_set_ap_completer_type(self: argparse.ArgumentParser, ap_completer_type: Type['ArgparseCompleter']) -> None:
"""
Set the ap_completer_type attribute of an argparse ArgumentParser.
Expand All @@ -984,7 +970,6 @@ def _ArgumentParser_set_ap_completer_type(self: argparse.ArgumentParser, ap_comp
############################################################################################################
# Patch ArgumentParser._check_value to support CompletionItems as choices
############################################################################################################
# noinspection PyPep8Naming
def _ArgumentParser_check_value(self: argparse.ArgumentParser, action: argparse.Action, value: Any) -> None:
"""
Custom override of ArgumentParser._check_value that supports CompletionItems as choices.
Expand Down Expand Up @@ -1018,7 +1003,6 @@ def _ArgumentParser_check_value(self: argparse.ArgumentParser, action: argparse.
############################################################################################################


# noinspection PyPep8Naming,PyProtectedMember
def _SubParsersAction_remove_parser(self: argparse._SubParsersAction, name: str) -> None: # type: ignore
"""
Removes a sub-parser from a sub-parsers group. Used to remove subcommands from a parser.
Expand Down Expand Up @@ -1047,7 +1031,6 @@ def _SubParsersAction_remove_parser(self: argparse._SubParsersAction, name: str)
del self._name_parser_map[cur_name]


# noinspection PyProtectedMember
setattr(argparse._SubParsersAction, 'remove_parser', _SubParsersAction_remove_parser)


Expand All @@ -1059,11 +1042,9 @@ def _SubParsersAction_remove_parser(self: argparse._SubParsersAction, name: str)
############################################################################################################


# noinspection PyCompatibility,PyShadowingBuiltins
class Cmd2HelpFormatter(argparse.RawTextHelpFormatter):
"""Custom help formatter to configure ordering of help text"""

# noinspection PyProtectedMember
def _format_usage(
self,
usage: Optional[str],
Expand Down Expand Up @@ -1126,7 +1107,6 @@ def _format_usage(
# End cmd2 customization

# helper for wrapping lines
# noinspection PyMissingOrEmptyDocstring,PyShadowingNames
def get_lines(parts: List[str], indent: str, prefix: Optional[str] = None) -> List[str]:
lines: List[str] = []
line: List[str] = []
Expand Down Expand Up @@ -1209,7 +1189,6 @@ def _format_action_invocation(self, action: argparse.Action) -> str:
return ', '.join(action.option_strings) + ' ' + args_string
# End cmd2 customization

# noinspection PyMethodMayBeStatic
def _determine_metavar(
self,
action: argparse.Action,
Expand All @@ -1234,7 +1213,6 @@ def _metavar_formatter(
) -> Callable[[int], Tuple[str, ...]]:
metavar = self._determine_metavar(action, default_metavar)

# noinspection PyMissingOrEmptyDocstring
def format(tuple_size: int) -> Tuple[str, ...]:
if isinstance(metavar, tuple):
return metavar
Expand All @@ -1243,7 +1221,6 @@ def format(tuple_size: int) -> Tuple[str, ...]:

return format

# noinspection PyProtectedMember
def _format_args(self, action: argparse.Action, default_metavar: Union[str, Tuple[str, ...]]) -> str:
"""Customized to handle ranged nargs and make other output less verbose"""
metavar = self._determine_metavar(action, default_metavar)
Expand Down Expand Up @@ -1272,7 +1249,6 @@ def _format_args(self, action: argparse.Action, default_metavar: Union[str, Tupl
return super()._format_args(action, default_metavar) # type: ignore[arg-type]


# noinspection PyCompatibility
class Cmd2ArgumentParser(argparse.ArgumentParser):
"""Custom ArgumentParser class that improves error and help output"""

Expand Down Expand Up @@ -1317,7 +1293,6 @@ def __init__(

self.set_ap_completer_type(ap_completer_type) # type: ignore[attr-defined]

# noinspection PyProtectedMember
def add_subparsers(self, **kwargs: Any) -> argparse._SubParsersAction: # type: ignore
"""
Custom override. Sets a default title if one was not given.
Expand Down Expand Up @@ -1346,7 +1321,6 @@ def error(self, message: str) -> NoReturn:
formatted_message = ansi.style_error(formatted_message)
self.exit(2, f'{formatted_message}\n\n')

# noinspection PyProtectedMember
def format_help(self) -> str:
"""Copy of format_help() from argparse.ArgumentParser with tweaks to separately display required parameters"""
formatter = self._get_formatter()
Expand Down
Loading

0 comments on commit 8ee89ee

Please sign in to comment.