Skip to content

Use latest version of mypy and fix type hinting accordingly #1239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "*"
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

[![Latest Version](https://img.shields.io/pypi/v/cmd2.svg?style=flat-square&label=latest%20stable%20version)](https://pypi.python.org/pypi/cmd2/)
[![GitHub Actions](https://github.com/python-cmd2/cmd2/workflows/CI/badge.svg)](https://github.com/python-cmd2/cmd2/actions?query=workflow%3ACI)
[![Azure Build status](https://python-cmd2.visualstudio.com/cmd2/_apis/build/status/python-cmd2.cmd2?branch=master)](https://python-cmd2.visualstudio.com/cmd2/_build/latest?definitionId=1&branch=master)
[![codecov](https://codecov.io/gh/python-cmd2/cmd2/branch/master/graph/badge.svg)](https://codecov.io/gh/python-cmd2/cmd2)
[![Documentation Status](https://readthedocs.org/projects/cmd2/badge/?version=latest)](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>

[![Screenshot](https://raw.githubusercontent.com/python-cmd2/cmd2/master/cmd2.png)](https://youtu.be/DDU_JH6cFsA)
Expand Down
4 changes: 2 additions & 2 deletions cmd2/argparse_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions cmd2/cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 5 additions & 4 deletions cmd2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')


Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
'doc8',
'flake8',
'invoke',
'mypy==0.902',
'mypy',
'nox',
"pytest>=4.6",
'pytest-cov',
Expand All @@ -80,7 +80,7 @@
],
'validate': [
'flake8',
'mypy==0.902',
'mypy',
'types-pkg-resources',
],
}
Expand Down
11 changes: 11 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)