summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Pipfile1
-rw-r--r--cmd2/argparse_custom.py9
-rw-r--r--cmd2/exceptions.py4
-rw-r--r--cmd2/transcript.py3
-rw-r--r--cmd2/utils.py20
5 files changed, 27 insertions, 10 deletions
diff --git a/Pipfile b/Pipfile
index 2bf8c8e5..41f8ef5b 100644
--- a/Pipfile
+++ b/Pipfile
@@ -22,6 +22,7 @@ invoke = "*"
ipython = "*"
isort = "*"
mock = {version = "*",markers = "python_version < '3.6'"}
+mypy = "*"
plumbum = "*"
pyreadline = {version = "*",sys_platform = "== 'win32'",markers = "python_version < '3.8'"}
pyreadline3 = {version = "*",sys_platform = "== 'win32'",markers = "python_version >= '3.8'"}
diff --git a/cmd2/argparse_custom.py b/cmd2/argparse_custom.py
index d3f819b2..2c71dec3 100644
--- a/cmd2/argparse_custom.py
+++ b/cmd2/argparse_custom.py
@@ -203,6 +203,7 @@ from argparse import (
from typing import (
Any,
Callable,
+ NoReturn,
Optional,
Tuple,
Type,
@@ -264,7 +265,7 @@ class CompletionItem(str):
return super().__new__(cls, value)
# noinspection PyUnusedLocal
- def __init__(self, value: object, desc: str = '', *args, **kwargs) -> None:
+ def __init__(self, value: object, desc: str = '', *args) -> None:
"""
CompletionItem Initializer
@@ -273,7 +274,7 @@ class CompletionItem(str):
:param args: args for str __init__
:param kwargs: kwargs for str __init__
"""
- super().__init__(*args, **kwargs)
+ super().__init__(*args)
self.description = desc
@@ -340,7 +341,7 @@ orig_actions_container_add_argument = argparse._ActionsContainer.add_argument
def _add_argument_wrapper(
self,
*args,
- nargs: Union[int, str, Tuple[int], Tuple[int, int], None] = None,
+ nargs: Union[int, str, Tuple[int], Tuple[int, int], Tuple[int, float], None] = None,
choices_provider: Optional[Callable] = None,
completer: Optional[Callable] = None,
suppress_tab_hint: bool = False,
@@ -812,7 +813,7 @@ class Cmd2ArgumentParser(argparse.ArgumentParser):
return super().add_subparsers(**kwargs)
- def error(self, message: str) -> None:
+ def error(self, message: str) -> NoReturn:
"""Custom override that applies custom formatting to the error message"""
lines = message.split('\n')
linum = 0
diff --git a/cmd2/exceptions.py b/cmd2/exceptions.py
index c662d8fa..39b7e333 100644
--- a/cmd2/exceptions.py
+++ b/cmd2/exceptions.py
@@ -49,7 +49,7 @@ class CompletionError(Exception):
- Tab completion hints
"""
- def __init__(self, *args, apply_style: bool = True, **kwargs):
+ def __init__(self, *args, apply_style: bool = True):
"""
Initializer for CompletionError
:param apply_style: If True, then ansi.style_error will be applied to the message text when printed.
@@ -59,7 +59,7 @@ class CompletionError(Exception):
self.apply_style = apply_style
# noinspection PyArgumentList
- super().__init__(*args, **kwargs)
+ super().__init__(*args)
############################################################################################################
diff --git a/cmd2/transcript.py b/cmd2/transcript.py
index 68fb7be0..5cd59ae8 100644
--- a/cmd2/transcript.py
+++ b/cmd2/transcript.py
@@ -60,6 +60,9 @@ class Cmd2TestCase(unittest.TestCase):
tfile.close()
def _test_transcript(self, fname: str, transcript):
+ if self.cmdapp is None:
+ return
+
line_num = 0
finished = False
line = ansi.strip_style(next(transcript))
diff --git a/cmd2/utils.py b/cmd2/utils.py
index 3f928e5f..236b2b0c 100644
--- a/cmd2/utils.py
+++ b/cmd2/utils.py
@@ -24,7 +24,9 @@ from typing import (
Dict,
Iterable,
List,
+ NamedTuple,
Optional,
+ OrderedDict,
TextIO,
Type,
Union,
@@ -161,7 +163,7 @@ def namedtuple_with_defaults(typename: str, field_names: Union[str, List[str]],
>>> Node(4)
Node(val=4, left=None, right=7)
"""
- T = collections.namedtuple(typename, field_names)
+ T: NamedTuple = collections.namedtuple(typename, field_names)
# noinspection PyProtectedMember,PyUnresolvedReferences
T.__new__.__defaults__ = (None,) * len(T._fields)
if isinstance(default_values, collections_abc.Mapping):
@@ -215,7 +217,7 @@ def remove_duplicates(list_to_prune: List) -> List:
:param list_to_prune: the list being pruned of duplicates
:return: The pruned list
"""
- temp_dict = collections.OrderedDict()
+ temp_dict: OrderedDict = collections.OrderedDict()
for item in list_to_prune:
temp_dict[item] = None
@@ -353,7 +355,13 @@ def find_editor() -> Optional[str]:
else:
editors = ['vim', 'vi', 'emacs', 'nano', 'pico', 'joe', 'code', 'subl', 'atom', 'gedit', 'geany', 'kate']
- paths = [p for p in os.getenv('PATH').split(os.path.pathsep) if not os.path.islink(p)]
+ # Get a list of every directory in the PATH environment variable and ignore symbolic links
+ env_path = os.getenv('PATH')
+ if env_path is None:
+ paths = []
+ else:
+ paths = [p for p in env_path.split(os.path.pathsep) if not os.path.islink(p)]
+
for editor, path in itertools.product(editors, paths):
editor_path = os.path.join(path, editor)
if os.path.isfile(editor_path) and os.access(editor_path, os.X_OK):
@@ -408,7 +416,11 @@ def get_exes_in_path(starts_with: str) -> List[str]:
return []
# Get a list of every directory in the PATH environment variable and ignore symbolic links
- paths = [p for p in os.getenv('PATH').split(os.path.pathsep) if not os.path.islink(p)]
+ env_path = os.getenv('PATH')
+ if env_path is None:
+ paths = []
+ else:
+ paths = [p for p in env_path.split(os.path.pathsep) if not os.path.islink(p)]
# Use a set to store exe names since there can be duplicates
exes_set = set()