diff --git a/blessed/__init__.py b/blessed/__init__.py index 5844b23d..9f607064 100644 --- a/blessed/__init__.py +++ b/blessed/__init__.py @@ -10,7 +10,7 @@ if _platform.system() == 'Windows': from blessed.win_terminal import Terminal else: - from blessed.terminal import Terminal # type: ignore + from blessed.terminal import Terminal # type: ignore[assignment] __all__ = ('Terminal',) __version__ = "1.25.0" diff --git a/blessed/formatters.py b/blessed/formatters.py index 1c68ac59..4664754f 100644 --- a/blessed/formatters.py +++ b/blessed/formatters.py @@ -1,7 +1,9 @@ """Sub-module providing sequence-formatting functions.""" +from __future__ import annotations + # std imports import platform -from typing import TYPE_CHECKING, Set, Dict, List, Type, Tuple, Union, TypeVar, Callable, Optional +from typing import TYPE_CHECKING, Set, Dict, List, Tuple, Union, Callable, Optional # local from blessed.colorspace import CGA_COLORS, X11_COLORNAMES_TO_RGB @@ -10,8 +12,6 @@ # local from blessed.terminal import Terminal -_T = TypeVar("_T") - # isort: off # curses if platform.system() == 'Windows': @@ -65,7 +65,8 @@ class ParameterizingString(str): '\x1b[91mcolor #9\x1b(B\x1b[m' """ - def __new__(cls: Type[_T], cap: str, normal: str = '', name: str = '') -> _T: + def __new__(cls, cap: str, normal: str = '', + name: str = '') -> ParameterizingString: """ Class constructor accepting 3 positional arguments. @@ -140,8 +141,8 @@ class ParameterizingProxyString(str): '\x1b[10G' """ - def __new__(cls: Type[_T], fmt_pair: Tuple[str, Callable[..., Tuple[object, ...]]], - normal: str = '', name: str = '') -> _T: + def __new__(cls, fmt_pair: Tuple[str, Callable[..., Tuple[object, ...]]], + normal: str = '', name: str = '') -> ParameterizingProxyString: """ Class constructor accepting 4 positional arguments. @@ -193,7 +194,7 @@ class FormattingString(str): '\x1b[94mBig Blue\x1b(B\x1b[m' """ - def __new__(cls: Type[_T], sequence: str, normal: str = '') -> _T: + def __new__(cls, sequence: str, normal: str = '') -> FormattingString: """ Class constructor accepting 2 positional arguments. @@ -252,7 +253,8 @@ class FormattingOtherString(str): '\x1b[C' """ - def __new__(cls: Type[_T], direct: ParameterizingString, target: ParameterizingString) -> _T: + def __new__(cls, direct: ParameterizingString, + target: ParameterizingString) -> FormattingOtherString: """ Class constructor accepting 2 positional arguments. @@ -280,7 +282,7 @@ class NullCallableString(str): unicode that may also act as a callable. """ - def __new__(cls: Type[_T]) -> _T: + def __new__(cls) -> NullCallableString: """Class constructor.""" return str.__new__(cls, '') diff --git a/blessed/keyboard.py b/blessed/keyboard.py index 24e35f45..993f3936 100644 --- a/blessed/keyboard.py +++ b/blessed/keyboard.py @@ -81,7 +81,7 @@ r';(?P\d+);(?P\d+)t') # DEC event pattern container -DECEventPattern = functools.namedtuple("DEC_EVENT_PATTERN", ["mode", "pattern"]) +DECEventPattern = namedtuple("DECEventPattern", ["mode", "pattern"]) # DEC event patterns - compiled regexes with metadata of the 'mode' that # triggered it, this prevents searching for bracketed paste or mouse modes @@ -1186,7 +1186,7 @@ def get_keyboard_codes() -> Dict[int, str]: # Merge in homemade KEY_TAB, KEY_KP_*, KEY_MENU added to our module space # Exclude *_PUA constants since they're internal implementation details # that will be remapped via KITTY_PUA_KEYCODE_OVERRIDE_MIXIN. - # Make sure to copy globals() since other threads might create or + # Make sure to copy globals() since other threads might create or # destroy globals while we iterate. keycodes.update((k, v) for k, v in globals().copy().items() if k.startswith('KEY_') and not k.endswith('_PUA')) diff --git a/blessed/sequences.py b/blessed/sequences.py index d635e27e..b5adeeae 100644 --- a/blessed/sequences.py +++ b/blessed/sequences.py @@ -1,4 +1,6 @@ """Module providing 'sequence awareness'.""" +from __future__ import annotations + # std imports import re import sys @@ -16,7 +18,7 @@ from blessed.terminal import Terminal # std imports -from typing import List, Type, Tuple, Pattern, TypeVar, Iterator, Optional +from typing import List, Tuple, Pattern, Iterator, Optional # SupportsIndex was added in Python 3.8 if sys.version_info >= (3, 8): @@ -25,8 +27,6 @@ else: SupportsIndex = int -_T = TypeVar("_T") - __all__ = ('Sequence', 'SequenceTextWrapper', 'iter_parse', 'measure_length') @@ -155,7 +155,7 @@ def __init__(self, width: int, term: 'Terminal', **kwargs: object) -> None: self.term = term textwrap.TextWrapper.__init__(self, width, **kwargs) - def _wrap_chunks(self, chunks): # type: ignore[no-untyped-def] + def _wrap_chunks(self, chunks: List[str]) -> List[str]: """ Sequence-aware variant of :meth:`textwrap.TextWrapper._wrap_chunks`. @@ -199,8 +199,8 @@ def _wrap_chunks(self, chunks): # type: ignore[no-untyped-def] lines.append(f'{indent}{"".join(cur_line)}') return lines - def _handle_long_word(self, # type: ignore[no-untyped-def] - reversed_chunks, cur_line, cur_len, width): + def _handle_long_word(self, reversed_chunks: List[str], cur_line: List[str], + cur_len: int, width: int) -> None: """ Sequence-aware :meth:`textwrap.TextWrapper._handle_long_word`. @@ -267,7 +267,7 @@ class Sequence(str): :meth:`ljust`, :meth:`center`, and :meth:`length`. """ - def __new__(cls: Type[_T], sequence_text: str, term: 'Terminal') -> _T: + def __new__(cls, sequence_text: str, term: 'Terminal') -> Sequence: """ Class constructor. diff --git a/blessed/terminal.py b/blessed/terminal.py index a9faaa76..564ec2dd 100644 --- a/blessed/terminal.py +++ b/blessed/terminal.py @@ -559,7 +559,7 @@ def pixel_width(self) -> int: return self._height_and_width().ws_xpixel @staticmethod - def _winsize(fd): # type: ignore[no-untyped-def] + def _winsize(fd: int) -> "WINSZ": """ Return named tuple describing size of the terminal by ``fd``. diff --git a/tox.ini b/tox.ini index da807fa8..e25ebb92 100644 --- a/tox.ini +++ b/tox.ini @@ -121,12 +121,16 @@ commands = [mypy] # Our typing information is very poorly done, it was designed by Erik Rose before python # typing was possible, and was considered "pythonic" at the time, but can't pass mustard -# at all, that 'term.any_thing' can be resolved to a termcap, and that terminical +# today, that 'term.any_thing' can be resolved to a termcap, and that terminical # capability can be used like a string, but also that it can be called, and those calls -# could be strings, or numbers, it's too much dynamism to handle. It even makes out library difficult -# to work with, - -disable_error_code = type-var,name-defined,operator,attr-defined,comparison-overlap,arg-type,no-any-return,has-type,no-untyped-call,return-value,call-overload,misc,override +# could be strings, or numbers -- it's too much dynamism for quality type checking. + +warn_unused_configs = true +warn_redundant_casts = true +warn_unused_ignores = true +disallow_untyped_defs = true +enable_error_code = ignore-without-code +disable_error_code = name-defined,operator,attr-defined,comparison-overlap,arg-type,no-any-return,has-type,return-value,call-overload,override [mypy-curses.has_key.*] ignore_missing_imports = True