summaryrefslogtreecommitdiff
path: root/cmd2
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2019-03-13 22:19:02 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2019-03-13 22:19:02 -0400
commitfdc24bf275a902c7927d8c6633a30540d8d95cca (patch)
tree86fbb95f935df0f6923b0485cf23c98108284b44 /cmd2
parent677e8bb845ecee0bc58035095fc599ffb074c00f (diff)
downloadcmd2-git-fdc24bf275a902c7927d8c6633a30540d8d95cca.tar.gz
Cleaned up some PyCharm warnings
Diffstat (limited to 'cmd2')
-rw-r--r--cmd2/clipboard.py2
-rw-r--r--cmd2/cmd2.py16
-rw-r--r--cmd2/history.py4
-rw-r--r--cmd2/pyscript_bridge.py1
-rw-r--r--cmd2/rl_utils.py15
-rw-r--r--cmd2/utils.py1
6 files changed, 27 insertions, 12 deletions
diff --git a/cmd2/clipboard.py b/cmd2/clipboard.py
index e0d1fc03..b2331649 100644
--- a/cmd2/clipboard.py
+++ b/cmd2/clipboard.py
@@ -10,7 +10,7 @@ import pyperclip
try:
from pyperclip.exceptions import PyperclipException
except ImportError: # pragma: no cover
- # noinspection PyUnresolvedReferences
+ # noinspection PyUnresolvedReferences,PyProtectedMember
from pyperclip import PyperclipException
# Can we access the clipboard? Should always be true on Windows and Mac, but only sometimes on Linux
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index e32b3180..08ca1b80 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -68,7 +68,7 @@ else:
if rl_type == RlType.PYREADLINE:
# Save the original pyreadline display completion function since we need to override it and restore it
- # noinspection PyProtectedMember
+ # noinspection PyProtectedMember,PyUnresolvedReferences
orig_pyreadline_display = readline.rl.mode._display_completions
elif rl_type == RlType.GNU:
@@ -104,6 +104,7 @@ except ImportError:
# Python 3.4 require contextlib2 for temporarily redirecting stderr and stdout
if sys.version_info < (3, 5):
+ # noinspection PyUnresolvedReferences
from contextlib2 import redirect_stdout
else:
from contextlib import redirect_stdout
@@ -704,6 +705,7 @@ class Cmd(cmd.Cmd):
if rl_type == RlType.GNU:
readline.set_completion_display_matches_hook(self._display_matches_gnu_readline)
elif rl_type == RlType.PYREADLINE:
+ # noinspection PyUnresolvedReferences
readline.rl.mode._display_completions = self._display_matches_pyreadline
def tokens_for_completion(self, line: str, begidx: int, endidx: int) -> Tuple[List[str], List[str]]:
@@ -1331,6 +1333,7 @@ class Cmd(cmd.Cmd):
# Print the header if one exists
if self.completion_header:
+ # noinspection PyUnresolvedReferences
readline.rl.mode.console.write('\n' + self.completion_header)
# Display matches using actual display function. This also redraws the prompt and line.
@@ -2178,6 +2181,7 @@ class Cmd(cmd.Cmd):
readline.set_completion_display_matches_hook(None)
rl_basic_quote_characters.value = old_basic_quotes
elif rl_type == RlType.PYREADLINE:
+ # noinspection PyUnresolvedReferences
readline.rl.mode._display_completions = orig_pyreadline_display
self.cmdqueue.clear()
@@ -3013,6 +3017,7 @@ class Cmd(cmd.Cmd):
# Save cmd2 history
saved_cmd2_history = []
for i in range(1, readline.get_current_history_length() + 1):
+ # noinspection PyArgumentList
saved_cmd2_history.append(readline.get_history_item(i))
readline.clear_history()
@@ -3045,6 +3050,7 @@ class Cmd(cmd.Cmd):
if rl_type == RlType.GNU:
readline.set_completion_display_matches_hook(None)
elif rl_type == RlType.PYREADLINE:
+ # noinspection PyUnresolvedReferences
readline.rl.mode._display_completions = self._display_matches_pyreadline
# Save off the current completer and set a new one in the Python console
@@ -3082,6 +3088,7 @@ class Cmd(cmd.Cmd):
# Save py's history
self.py_history.clear()
for i in range(1, readline.get_current_history_length() + 1):
+ # noinspection PyArgumentList
self.py_history.append(readline.get_history_item(i))
readline.clear_history()
@@ -3159,10 +3166,12 @@ class Cmd(cmd.Cmd):
exit_msg = 'Leaving IPython, back to {}'.format(sys.argv[0])
if self.locals_in_py:
- def load_ipy(self, app):
+ # noinspection PyUnusedLocal
+ def load_ipy(cmd2_instance, app):
embed(banner1=banner, exit_msg=exit_msg)
load_ipy(self, bridge)
else:
+ # noinspection PyUnusedLocal
def load_ipy(app):
embed(banner1=banner, exit_msg=exit_msg)
load_ipy(bridge)
@@ -3383,7 +3392,7 @@ class Cmd(cmd.Cmd):
command = utils.quote_string_if_needed(os.path.expanduser(self.editor))
if args.file_path:
- command += " " + utils.quote_string_if_needed(os.path.expanduser(args.file_path))
+ command += " " + utils.quote_string_if_needed(os.path.expaclass nduser(args.file_path))
self.do_shell(command)
@@ -3564,6 +3573,7 @@ class Cmd(cmd.Cmd):
if rl_type == RlType.GNU:
sys.stderr.write(terminal_str)
elif rl_type == RlType.PYREADLINE:
+ # noinspection PyUnresolvedReferences
readline.rl.mode.console.write(terminal_str)
# Redraw the prompt and input lines
diff --git a/cmd2/history.py b/cmd2/history.py
index 729cc6e3..7cc36bfc 100644
--- a/cmd2/history.py
+++ b/cmd2/history.py
@@ -128,12 +128,12 @@ class History(list):
# \s*$ match any whitespace at the end of the input. This is here so
# you don't have to trim the input
#
- spanpattern = re.compile(r'^\s*(?P<start>-?[1-9]{1}\d*)?(?P<separator>:|(\.{2,}))?(?P<end>-?[1-9]{1}\d*)?\s*$')
+ spanpattern = re.compile(r'^\s*(?P<start>-?[1-9]\d*)?(?P<separator>:|(\.{2,}))?(?P<end>-?[1-9]\d*)?\s*$')
def span(self, span: str) -> List[HistoryItem]:
"""Return an index or slice of the History list,
- :param raw: string containing an index or a slice
+ :param span: string containing an index or a slice
:return: a list of HistoryItems
This method can accommodate input in any of these forms:
diff --git a/cmd2/pyscript_bridge.py b/cmd2/pyscript_bridge.py
index f3ce841d..e1568b7c 100644
--- a/cmd2/pyscript_bridge.py
+++ b/cmd2/pyscript_bridge.py
@@ -14,6 +14,7 @@ from .utils import namedtuple_with_defaults, StdSim
# Python 3.4 require contextlib2 for temporarily redirecting stderr and stdout
if sys.version_info < (3, 5):
+ # noinspection PyUnresolvedReferences
from contextlib2 import redirect_stdout, redirect_stderr
else:
from contextlib import redirect_stdout, redirect_stderr
diff --git a/cmd2/rl_utils.py b/cmd2/rl_utils.py
index fdddca0b..b5ba8e4a 100644
--- a/cmd2/rl_utils.py
+++ b/cmd2/rl_utils.py
@@ -7,6 +7,7 @@ import sys
# Prefer statically linked gnureadline if available (for macOS compatibility due to issues with libedit)
try:
+ # noinspection PyPackageRequirements
import gnureadline as readline
except ImportError:
# Try to import readline, but allow failure for convenience in Windows unit testing
@@ -41,7 +42,7 @@ if 'pyreadline' in sys.modules:
# Check if we are running in a terminal
if sys.stdout.isatty(): # pragma: no cover
- # noinspection PyPep8Naming
+ # noinspection PyPep8Naming,PyUnresolvedReferences
def enable_win_vt100(handle: HANDLE) -> bool:
"""
Enables VT100 character sequences in a Windows console
@@ -71,7 +72,9 @@ if 'pyreadline' in sys.modules:
# Enable VT100 sequences for stdout and stderr
STD_OUT_HANDLE = -11
STD_ERROR_HANDLE = -12
+ # noinspection PyUnresolvedReferences
vt100_stdout_support = enable_win_vt100(readline.rl.console.GetStdHandle(STD_OUT_HANDLE))
+ # noinspection PyUnresolvedReferences
vt100_stderr_support = enable_win_vt100(readline.rl.console.GetStdHandle(STD_ERROR_HANDLE))
vt100_support = vt100_stdout_support and vt100_stderr_support
@@ -82,14 +85,14 @@ if 'pyreadline' in sys.modules:
try:
getattr(readline, 'redisplay')
except AttributeError:
- # noinspection PyProtectedMember
+ # noinspection PyProtectedMember,PyUnresolvedReferences
readline.redisplay = readline.rl.mode._update_line
# readline.remove_history_item()
try:
getattr(readline, 'remove_history_item')
except AttributeError:
- # noinspection PyProtectedMember
+ # noinspection PyProtectedMember,PyUnresolvedReferences
def pyreadline_remove_history_item(pos: int) -> None:
"""
An implementation of remove_history_item() for pyreadline
@@ -121,7 +124,7 @@ elif 'gnureadline' in sys.modules or 'readline' in sys.modules:
vt100_support = True
-# noinspection PyProtectedMember
+# noinspection PyProtectedMember,PyUnresolvedReferences
def rl_force_redisplay() -> None: # pragma: no cover
"""
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
readline.rl.mode._update_line()
-# noinspection PyProtectedMember
+# noinspection PyProtectedMember, PyUnresolvedReferences
def rl_get_point() -> int: # pragma: no cover
"""
Returns the offset of the current cursor position in rl_line_buffer
@@ -159,7 +162,7 @@ def rl_get_point() -> int: # pragma: no cover
return 0
-# noinspection PyProtectedMember
+# noinspection PyProtectedMember, PyUnresolvedReferences
def rl_set_prompt(prompt: str) -> None: # pragma: no cover
"""
Sets readline's prompt
diff --git a/cmd2/utils.py b/cmd2/utils.py
index a8760a65..c43ff62a 100644
--- a/cmd2/utils.py
+++ b/cmd2/utils.py
@@ -88,6 +88,7 @@ def namedtuple_with_defaults(typename: str, field_names: Union[str, List[str]],
Node(val=4, left=None, right=7)
"""
T = collections.namedtuple(typename, field_names)
+ # noinspection PyProtectedMember,PyUnresolvedReferences
T.__new__.__defaults__ = (None,) * len(T._fields)
if isinstance(default_values, collections.Mapping):
prototype = T(**default_values)