Skip to content

Commit fdc24bf

Browse files
committed
Cleaned up some PyCharm warnings
1 parent 677e8bb commit fdc24bf

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

cmd2/clipboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
try:
1111
from pyperclip.exceptions import PyperclipException
1212
except ImportError: # pragma: no cover
13-
# noinspection PyUnresolvedReferences
13+
# noinspection PyUnresolvedReferences,PyProtectedMember
1414
from pyperclip import PyperclipException
1515

1616
# Can we access the clipboard? Should always be true on Windows and Mac, but only sometimes on Linux

cmd2/cmd2.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
if rl_type == RlType.PYREADLINE:
6969

7070
# Save the original pyreadline display completion function since we need to override it and restore it
71-
# noinspection PyProtectedMember
71+
# noinspection PyProtectedMember,PyUnresolvedReferences
7272
orig_pyreadline_display = readline.rl.mode._display_completions
7373

7474
elif rl_type == RlType.GNU:
@@ -104,6 +104,7 @@ def __subclasshook__(cls, C):
104104

105105
# Python 3.4 require contextlib2 for temporarily redirecting stderr and stdout
106106
if sys.version_info < (3, 5):
107+
# noinspection PyUnresolvedReferences
107108
from contextlib2 import redirect_stdout
108109
else:
109110
from contextlib import redirect_stdout
@@ -704,6 +705,7 @@ def reset_completion_defaults(self) -> None:
704705
if rl_type == RlType.GNU:
705706
readline.set_completion_display_matches_hook(self._display_matches_gnu_readline)
706707
elif rl_type == RlType.PYREADLINE:
708+
# noinspection PyUnresolvedReferences
707709
readline.rl.mode._display_completions = self._display_matches_pyreadline
708710

709711
def tokens_for_completion(self, line: str, begidx: int, endidx: int) -> Tuple[List[str], List[str]]:
@@ -1331,6 +1333,7 @@ def _display_matches_pyreadline(self, matches: List[str]) -> None: # pragma: no
13311333

13321334
# Print the header if one exists
13331335
if self.completion_header:
1336+
# noinspection PyUnresolvedReferences
13341337
readline.rl.mode.console.write('\n' + self.completion_header)
13351338

13361339
# Display matches using actual display function. This also redraws the prompt and line.
@@ -2178,6 +2181,7 @@ def _cmdloop(self) -> bool:
21782181
readline.set_completion_display_matches_hook(None)
21792182
rl_basic_quote_characters.value = old_basic_quotes
21802183
elif rl_type == RlType.PYREADLINE:
2184+
# noinspection PyUnresolvedReferences
21812185
readline.rl.mode._display_completions = orig_pyreadline_display
21822186

21832187
self.cmdqueue.clear()
@@ -3013,6 +3017,7 @@ def py_quit():
30133017
# Save cmd2 history
30143018
saved_cmd2_history = []
30153019
for i in range(1, readline.get_current_history_length() + 1):
3020+
# noinspection PyArgumentList
30163021
saved_cmd2_history.append(readline.get_history_item(i))
30173022

30183023
readline.clear_history()
@@ -3045,6 +3050,7 @@ def py_quit():
30453050
if rl_type == RlType.GNU:
30463051
readline.set_completion_display_matches_hook(None)
30473052
elif rl_type == RlType.PYREADLINE:
3053+
# noinspection PyUnresolvedReferences
30483054
readline.rl.mode._display_completions = self._display_matches_pyreadline
30493055

30503056
# Save off the current completer and set a new one in the Python console
@@ -3082,6 +3088,7 @@ def py_quit():
30823088
# Save py's history
30833089
self.py_history.clear()
30843090
for i in range(1, readline.get_current_history_length() + 1):
3091+
# noinspection PyArgumentList
30853092
self.py_history.append(readline.get_history_item(i))
30863093

30873094
readline.clear_history()
@@ -3159,10 +3166,12 @@ def do_ipy(self, _: argparse.Namespace) -> None:
31593166
exit_msg = 'Leaving IPython, back to {}'.format(sys.argv[0])
31603167

31613168
if self.locals_in_py:
3162-
def load_ipy(self, app):
3169+
# noinspection PyUnusedLocal
3170+
def load_ipy(cmd2_instance, app):
31633171
embed(banner1=banner, exit_msg=exit_msg)
31643172
load_ipy(self, bridge)
31653173
else:
3174+
# noinspection PyUnusedLocal
31663175
def load_ipy(app):
31673176
embed(banner1=banner, exit_msg=exit_msg)
31683177
load_ipy(bridge)
@@ -3383,7 +3392,7 @@ def do_edit(self, args: argparse.Namespace) -> None:
33833392

33843393
command = utils.quote_string_if_needed(os.path.expanduser(self.editor))
33853394
if args.file_path:
3386-
command += " " + utils.quote_string_if_needed(os.path.expanduser(args.file_path))
3395+
command += " " + utils.quote_string_if_needed(os.path.expaclass nduser(args.file_path))
33873396

33883397
self.do_shell(command)
33893398

@@ -3564,6 +3573,7 @@ def async_alert(self, alert_msg: str, new_prompt: Optional[str] = None) -> None:
35643573
if rl_type == RlType.GNU:
35653574
sys.stderr.write(terminal_str)
35663575
elif rl_type == RlType.PYREADLINE:
3576+
# noinspection PyUnresolvedReferences
35673577
readline.rl.mode.console.write(terminal_str)
35683578

35693579
# Redraw the prompt and input lines

cmd2/history.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,12 @@ def get(self, index: Union[int, str]) -> HistoryItem:
128128
# \s*$ match any whitespace at the end of the input. This is here so
129129
# you don't have to trim the input
130130
#
131-
spanpattern = re.compile(r'^\s*(?P<start>-?[1-9]{1}\d*)?(?P<separator>:|(\.{2,}))?(?P<end>-?[1-9]{1}\d*)?\s*$')
131+
spanpattern = re.compile(r'^\s*(?P<start>-?[1-9]\d*)?(?P<separator>:|(\.{2,}))?(?P<end>-?[1-9]\d*)?\s*$')
132132

133133
def span(self, span: str) -> List[HistoryItem]:
134134
"""Return an index or slice of the History list,
135135
136-
:param raw: string containing an index or a slice
136+
:param span: string containing an index or a slice
137137
:return: a list of HistoryItems
138138
139139
This method can accommodate input in any of these forms:

cmd2/pyscript_bridge.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
# Python 3.4 require contextlib2 for temporarily redirecting stderr and stdout
1616
if sys.version_info < (3, 5):
17+
# noinspection PyUnresolvedReferences
1718
from contextlib2 import redirect_stdout, redirect_stderr
1819
else:
1920
from contextlib import redirect_stdout, redirect_stderr

cmd2/rl_utils.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
# Prefer statically linked gnureadline if available (for macOS compatibility due to issues with libedit)
99
try:
10+
# noinspection PyPackageRequirements
1011
import gnureadline as readline
1112
except ImportError:
1213
# Try to import readline, but allow failure for convenience in Windows unit testing
@@ -41,7 +42,7 @@ class RlType(Enum):
4142

4243
# Check if we are running in a terminal
4344
if sys.stdout.isatty(): # pragma: no cover
44-
# noinspection PyPep8Naming
45+
# noinspection PyPep8Naming,PyUnresolvedReferences
4546
def enable_win_vt100(handle: HANDLE) -> bool:
4647
"""
4748
Enables VT100 character sequences in a Windows console
@@ -71,7 +72,9 @@ def enable_win_vt100(handle: HANDLE) -> bool:
7172
# Enable VT100 sequences for stdout and stderr
7273
STD_OUT_HANDLE = -11
7374
STD_ERROR_HANDLE = -12
75+
# noinspection PyUnresolvedReferences
7476
vt100_stdout_support = enable_win_vt100(readline.rl.console.GetStdHandle(STD_OUT_HANDLE))
77+
# noinspection PyUnresolvedReferences
7578
vt100_stderr_support = enable_win_vt100(readline.rl.console.GetStdHandle(STD_ERROR_HANDLE))
7679
vt100_support = vt100_stdout_support and vt100_stderr_support
7780

@@ -82,14 +85,14 @@ def enable_win_vt100(handle: HANDLE) -> bool:
8285
try:
8386
getattr(readline, 'redisplay')
8487
except AttributeError:
85-
# noinspection PyProtectedMember
88+
# noinspection PyProtectedMember,PyUnresolvedReferences
8689
readline.redisplay = readline.rl.mode._update_line
8790

8891
# readline.remove_history_item()
8992
try:
9093
getattr(readline, 'remove_history_item')
9194
except AttributeError:
92-
# noinspection PyProtectedMember
95+
# noinspection PyProtectedMember,PyUnresolvedReferences
9396
def pyreadline_remove_history_item(pos: int) -> None:
9497
"""
9598
An implementation of remove_history_item() for pyreadline
@@ -121,7 +124,7 @@ def pyreadline_remove_history_item(pos: int) -> None:
121124
vt100_support = True
122125

123126

124-
# noinspection PyProtectedMember
127+
# noinspection PyProtectedMember,PyUnresolvedReferences
125128
def rl_force_redisplay() -> None: # pragma: no cover
126129
"""
127130
Causes readline to display the prompt and input text wherever the cursor is and start
@@ -144,7 +147,7 @@ def rl_force_redisplay() -> None: # pragma: no cover
144147
readline.rl.mode._update_line()
145148

146149

147-
# noinspection PyProtectedMember
150+
# noinspection PyProtectedMember, PyUnresolvedReferences
148151
def rl_get_point() -> int: # pragma: no cover
149152
"""
150153
Returns the offset of the current cursor position in rl_line_buffer
@@ -159,7 +162,7 @@ def rl_get_point() -> int: # pragma: no cover
159162
return 0
160163

161164

162-
# noinspection PyProtectedMember
165+
# noinspection PyProtectedMember, PyUnresolvedReferences
163166
def rl_set_prompt(prompt: str) -> None: # pragma: no cover
164167
"""
165168
Sets readline's prompt

cmd2/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def namedtuple_with_defaults(typename: str, field_names: Union[str, List[str]],
8888
Node(val=4, left=None, right=7)
8989
"""
9090
T = collections.namedtuple(typename, field_names)
91+
# noinspection PyProtectedMember,PyUnresolvedReferences
9192
T.__new__.__defaults__ = (None,) * len(T._fields)
9293
if isinstance(default_values, collections.Mapping):
9394
prototype = T(**default_values)

0 commit comments

Comments
 (0)