Skip to content

Commit ccb50f3

Browse files
committed
Start making small changes to fix mypy warnings
1 parent 9c60ac6 commit ccb50f3

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ invoke = "*"
2222
ipython = "*"
2323
isort = "*"
2424
mock = {version = "*",markers = "python_version < '3.6'"}
25+
mypy = "*"
2526
plumbum = "*"
2627
pyreadline = {version = "*",sys_platform = "== 'win32'",markers = "python_version < '3.8'"}
2728
pyreadline3 = {version = "*",sys_platform = "== 'win32'",markers = "python_version >= '3.8'"}

cmd2/argparse_custom.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def my_completer(self, text, line, begidx, endidx, arg_tokens)
203203
from typing import (
204204
Any,
205205
Callable,
206+
NoReturn,
206207
Optional,
207208
Tuple,
208209
Type,
@@ -264,7 +265,7 @@ def __new__(cls, value: object, *args, **kwargs) -> str:
264265
return super().__new__(cls, value)
265266

266267
# noinspection PyUnusedLocal
267-
def __init__(self, value: object, desc: str = '', *args, **kwargs) -> None:
268+
def __init__(self, value: object, desc: str = '', *args) -> None:
268269
"""
269270
CompletionItem Initializer
270271
@@ -273,7 +274,7 @@ def __init__(self, value: object, desc: str = '', *args, **kwargs) -> None:
273274
:param args: args for str __init__
274275
:param kwargs: kwargs for str __init__
275276
"""
276-
super().__init__(*args, **kwargs)
277+
super().__init__(*args)
277278
self.description = desc
278279

279280

@@ -340,7 +341,7 @@ def set_completer(action: argparse.Action, completer: Callable) -> None:
340341
def _add_argument_wrapper(
341342
self,
342343
*args,
343-
nargs: Union[int, str, Tuple[int], Tuple[int, int], None] = None,
344+
nargs: Union[int, str, Tuple[int], Tuple[int, int], Tuple[int, float], None] = None,
344345
choices_provider: Optional[Callable] = None,
345346
completer: Optional[Callable] = None,
346347
suppress_tab_hint: bool = False,
@@ -812,7 +813,7 @@ def add_subparsers(self, **kwargs):
812813

813814
return super().add_subparsers(**kwargs)
814815

815-
def error(self, message: str) -> None:
816+
def error(self, message: str) -> NoReturn:
816817
"""Custom override that applies custom formatting to the error message"""
817818
lines = message.split('\n')
818819
linum = 0

cmd2/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class CompletionError(Exception):
4949
- Tab completion hints
5050
"""
5151

52-
def __init__(self, *args, apply_style: bool = True, **kwargs):
52+
def __init__(self, *args, apply_style: bool = True):
5353
"""
5454
Initializer for CompletionError
5555
:param apply_style: If True, then ansi.style_error will be applied to the message text when printed.
@@ -59,7 +59,7 @@ def __init__(self, *args, apply_style: bool = True, **kwargs):
5959
self.apply_style = apply_style
6060

6161
# noinspection PyArgumentList
62-
super().__init__(*args, **kwargs)
62+
super().__init__(*args)
6363

6464

6565
############################################################################################################

cmd2/transcript.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def _fetchTranscripts(self):
6060
tfile.close()
6161

6262
def _test_transcript(self, fname: str, transcript):
63+
if self.cmdapp is None:
64+
return
65+
6366
line_num = 0
6467
finished = False
6568
line = ansi.strip_style(next(transcript))

cmd2/utils.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
Dict,
2525
Iterable,
2626
List,
27+
NamedTuple,
2728
Optional,
29+
OrderedDict,
2830
TextIO,
2931
Type,
3032
Union,
@@ -161,7 +163,7 @@ def namedtuple_with_defaults(typename: str, field_names: Union[str, List[str]],
161163
>>> Node(4)
162164
Node(val=4, left=None, right=7)
163165
"""
164-
T = collections.namedtuple(typename, field_names)
166+
T: NamedTuple = collections.namedtuple(typename, field_names)
165167
# noinspection PyProtectedMember,PyUnresolvedReferences
166168
T.__new__.__defaults__ = (None,) * len(T._fields)
167169
if isinstance(default_values, collections_abc.Mapping):
@@ -215,7 +217,7 @@ def remove_duplicates(list_to_prune: List) -> List:
215217
:param list_to_prune: the list being pruned of duplicates
216218
:return: The pruned list
217219
"""
218-
temp_dict = collections.OrderedDict()
220+
temp_dict: OrderedDict = collections.OrderedDict()
219221
for item in list_to_prune:
220222
temp_dict[item] = None
221223

@@ -353,7 +355,13 @@ def find_editor() -> Optional[str]:
353355
else:
354356
editors = ['vim', 'vi', 'emacs', 'nano', 'pico', 'joe', 'code', 'subl', 'atom', 'gedit', 'geany', 'kate']
355357

356-
paths = [p for p in os.getenv('PATH').split(os.path.pathsep) if not os.path.islink(p)]
358+
# Get a list of every directory in the PATH environment variable and ignore symbolic links
359+
env_path = os.getenv('PATH')
360+
if env_path is None:
361+
paths = []
362+
else:
363+
paths = [p for p in env_path.split(os.path.pathsep) if not os.path.islink(p)]
364+
357365
for editor, path in itertools.product(editors, paths):
358366
editor_path = os.path.join(path, editor)
359367
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]:
408416
return []
409417

410418
# Get a list of every directory in the PATH environment variable and ignore symbolic links
411-
paths = [p for p in os.getenv('PATH').split(os.path.pathsep) if not os.path.islink(p)]
419+
env_path = os.getenv('PATH')
420+
if env_path is None:
421+
paths = []
422+
else:
423+
paths = [p for p in env_path.split(os.path.pathsep) if not os.path.islink(p)]
412424

413425
# Use a set to store exe names since there can be duplicates
414426
exes_set = set()

0 commit comments

Comments
 (0)