Skip to content

Commit 97f14b2

Browse files
authored
Merge pull request #1060 from python-cmd2/mypy
Start making small changes to fix mypy warnings
2 parents 9c60ac6 + fa0b55c commit 97f14b2

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
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: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
Dict,
2525
Iterable,
2626
List,
27+
NamedTuple,
2728
Optional,
2829
TextIO,
2930
Type,
@@ -161,7 +162,7 @@ def namedtuple_with_defaults(typename: str, field_names: Union[str, List[str]],
161162
>>> Node(4)
162163
Node(val=4, left=None, right=7)
163164
"""
164-
T = collections.namedtuple(typename, field_names)
165+
T: NamedTuple = collections.namedtuple(typename, field_names)
165166
# noinspection PyProtectedMember,PyUnresolvedReferences
166167
T.__new__.__defaults__ = (None,) * len(T._fields)
167168
if isinstance(default_values, collections_abc.Mapping):
@@ -353,7 +354,13 @@ def find_editor() -> Optional[str]:
353354
else:
354355
editors = ['vim', 'vi', 'emacs', 'nano', 'pico', 'joe', 'code', 'subl', 'atom', 'gedit', 'geany', 'kate']
355356

356-
paths = [p for p in os.getenv('PATH').split(os.path.pathsep) if not os.path.islink(p)]
357+
# Get a list of every directory in the PATH environment variable and ignore symbolic links
358+
env_path = os.getenv('PATH')
359+
if env_path is None:
360+
paths = []
361+
else:
362+
paths = [p for p in env_path.split(os.path.pathsep) if not os.path.islink(p)]
363+
357364
for editor, path in itertools.product(editors, paths):
358365
editor_path = os.path.join(path, editor)
359366
if os.path.isfile(editor_path) and os.access(editor_path, os.X_OK):
@@ -408,7 +415,11 @@ def get_exes_in_path(starts_with: str) -> List[str]:
408415
return []
409416

410417
# 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)]
418+
env_path = os.getenv('PATH')
419+
if env_path is None:
420+
paths = []
421+
else:
422+
paths = [p for p in env_path.split(os.path.pathsep) if not os.path.islink(p)]
412423

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

0 commit comments

Comments
 (0)