diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2022-07-14 12:59:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-14 12:59:16 -0400 |
commit | e95af81acb9c6829c969f76e40658356a4808edb (patch) | |
tree | b728a33789c33cae913abb16b8d40ee2dd6ff7cf | |
parent | f38194860572c32c4c1f475b16a901eb832d34e6 (diff) | |
download | cmd2-git-e95af81acb9c6829c969f76e40658356a4808edb.tar.gz |
Use latest version of mypy and fix type hinting accordingly (#1239)
* Use latest version of mypy and fix type hinting accordingly
Also:
- Update Pipfile to never require mock since we only support Python 3.6+
- Remove Azure Pipelines badge from Readme and fix section links there
- Added an "inv format" task to run black and isort to auto-format all code before a commit
* Try to fix type errors on versions prior to 3.8
* Restored correct types in argparse_custom.py
-rw-r--r-- | Pipfile | 1 | ||||
-rwxr-xr-x | README.md | 7 | ||||
-rw-r--r-- | cmd2/argparse_custom.py | 4 | ||||
-rw-r--r-- | cmd2/cmd2.py | 4 | ||||
-rw-r--r-- | cmd2/utils.py | 9 | ||||
-rwxr-xr-x | setup.py | 4 | ||||
-rw-r--r-- | tasks.py | 11 |
7 files changed, 26 insertions, 14 deletions
@@ -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 = "*" @@ -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) <a href="https://discord.gg/RpVG6tk"><img src="https://img.shields.io/badge/chat-on%20discord-7289da.svg" alt="Chat"></a> <p align="center"> - <a href="#main-features">Main Features</a> • + <a href="#the-developers-toolbox">Develper's Toolbox</a> • + <a href="#philosophy">Philosophy</a> • <a href="#installation">Installation</a> • + <a href="#documentation">Documentation</a> • <a href="#tutorials">Tutorials</a> • + <a href="#hello-world">Hello World</a> • <a href="#projects-using-cmd2">Projects using cmd2</a> • - <a href="#version-two-notes">Version 2.0 Notes</a> </p> [](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 @@ setattr(argparse.ArgumentParser, '_check_value', _ArgumentParser_check_value) ############################################################################################################ # 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 @@ class Cmd2ArgumentParser(argparse.ArgumentParser): 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 @@ class Cmd(cmd.Cmd): 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 @@ class Cmd(cmd.Cmd): 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 @@ from .argparse_custom import ( 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 @@ class ProcReader: 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: @@ -68,7 +68,7 @@ EXTRAS_REQUIRE = { 'doc8', 'flake8', 'invoke', - 'mypy==0.902', + 'mypy', 'nox', "pytest>=4.6", 'pytest-cov', @@ -80,7 +80,7 @@ EXTRAS_REQUIRE = { ], 'validate': [ 'flake8', - 'mypy==0.902', + 'mypy', 'types-pkg-resources', ], } @@ -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) |