diff --git a/Pipfile b/Pipfile
index 39a0911f..f0e94a8b 100644
--- a/Pipfile
+++ b/Pipfile
@@ -20,7 +20,6 @@ gnureadline = {version = "*",sys_platform = "== 'darwin'"}
invoke = "*"
ipython = "*"
isort = "*"
-mock = {version = "*",markers = "python_version < '3.6'"}
mypy = "*"
pyreadline3 = {version = ">=3.4",sys_platform = "== 'win32'"}
pytest = "*"
diff --git a/README.md b/README.md
index 080d9094..dbf7af1c 100755
--- a/README.md
+++ b/README.md
@@ -2,18 +2,19 @@
[](https://pypi.python.org/pypi/cmd2/)
[](https://github.com/python-cmd2/cmd2/actions?query=workflow%3ACI)
-[](https://python-cmd2.visualstudio.com/cmd2/_build/latest?definitionId=1&branch=master)
[](https://codecov.io/gh/python-cmd2/cmd2)
[](http://cmd2.readthedocs.io/en/latest/?badge=latest)
- Main Features • + Develper's Toolbox • + Philosophy • Installation • + Documentation • Tutorials • + Hello World • Projects using cmd2 • - Version 2.0 Notes
[](https://youtu.be/DDU_JH6cFsA) diff --git a/cmd2/argparse_custom.py b/cmd2/argparse_custom.py index 80e405f3..fea6d9cd 100644 --- a/cmd2/argparse_custom.py +++ b/cmd2/argparse_custom.py @@ -1033,7 +1033,7 @@ def _ArgumentParser_check_value(self: argparse.ArgumentParser, action: argparse. ############################################################################################################ # noinspection PyPep8Naming,PyProtectedMember -def _SubParsersAction_remove_parser(self: argparse._SubParsersAction, name: str) -> None: +def _SubParsersAction_remove_parser(self: argparse._SubParsersAction, name: str) -> None: # type: ignore """ Removes a sub-parser from a sub-parsers group. Used to remove subcommands from a parser. @@ -1333,7 +1333,7 @@ def __init__( self.set_ap_completer_type(ap_completer_type) # type: ignore[attr-defined] # noinspection PyProtectedMember - def add_subparsers(self, **kwargs: Any) -> argparse._SubParsersAction: + def add_subparsers(self, **kwargs: Any) -> argparse._SubParsersAction: # type: ignore """ Custom override. Sets a default title if one was not given. diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 72b26566..7fb85a1a 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -4426,7 +4426,7 @@ def do_ipy(self, _: argparse.Namespace) -> Optional[bool]: # pragma: no cover local_vars['self'] = self # Configure IPython - config = TraitletsLoader.Config() + config = TraitletsLoader.Config() # type: ignore config.InteractiveShell.banner2 = ( 'Entering an IPython shell. Type exit, quit, or Ctrl-D to exit.\n' f'Run CLI commands with: {self.py_bridge_name}("command ...")\n' @@ -5256,7 +5256,7 @@ def cmdloop(self, intro: Optional[str] = None) -> int: # type: ignore[override] import signal original_sigint_handler = signal.getsignal(signal.SIGINT) - signal.signal(signal.SIGINT, self.sigint_handler) + signal.signal(signal.SIGINT, self.sigint_handler) # type: ignore # Grab terminal lock before the command line prompt has been drawn by readline self.terminal_lock.acquire() diff --git a/cmd2/utils.py b/cmd2/utils.py index 5856b41a..295edb2f 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -41,12 +41,10 @@ if TYPE_CHECKING: # pragma: no cover import cmd2 # noqa: F401 - PopenTextIO = subprocess.Popen[bytes] - + PopenTextIO = subprocess.Popen[str] else: PopenTextIO = subprocess.Popen - _T = TypeVar('_T') @@ -670,12 +668,15 @@ def _reader_thread_func(self, read_stdout: bool) -> None: self._write_bytes(write_stream, available) @staticmethod - def _write_bytes(stream: Union[StdSim, TextIO], to_write: bytes) -> None: + def _write_bytes(stream: Union[StdSim, TextIO], to_write: Union[bytes, str]) -> None: """ Write bytes to a stream :param stream: the stream being written to :param to_write: the bytes being written """ + if isinstance(to_write, str): + to_write = to_write.encode() + try: stream.buffer.write(to_write) except BrokenPipeError: diff --git a/setup.py b/setup.py index 9c133df9..591ba9f8 100755 --- a/setup.py +++ b/setup.py @@ -68,7 +68,7 @@ 'doc8', 'flake8', 'invoke', - 'mypy==0.902', + 'mypy', 'nox', "pytest>=4.6", 'pytest-cov', @@ -80,7 +80,7 @@ ], 'validate': [ 'flake8', - 'mypy==0.902', + 'mypy', 'types-pkg-resources', ], } diff --git a/tasks.py b/tasks.py index 58bd1df8..a55661d8 100644 --- a/tasks.py +++ b/tasks.py @@ -353,3 +353,14 @@ def flake8(context): namespace.add_task(flake8) + + +# Black and isort auto-formatting +@invoke.task() +def format(context): + """Run black and isort auto-formatting for code style enforcement""" + with context.cd(TASK_ROOT_STR): + context.run("black . && isort .") + + +namespace.add_task(format)