Skip to content
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
2 changes: 1 addition & 1 deletion blessed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
20 changes: 11 additions & 9 deletions blessed/formatters.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,8 +12,6 @@
# local
from blessed.terminal import Terminal

_T = TypeVar("_T")

# isort: off
# curses
if platform.system() == 'Windows':
Expand Down Expand Up @@ -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 = '<not specified>') -> _T:
def __new__(cls, cap: str, normal: str = '',
name: str = '<not specified>') -> ParameterizingString:
"""
Class constructor accepting 3 positional arguments.

Expand Down Expand Up @@ -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 = '<not specified>') -> _T:
def __new__(cls, fmt_pair: Tuple[str, Callable[..., Tuple[object, ...]]],
normal: str = '', name: str = '<not specified>') -> ParameterizingProxyString:
"""
Class constructor accepting 4 positional arguments.

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

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

Expand Down Expand Up @@ -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, '')

Expand Down
4 changes: 2 additions & 2 deletions blessed/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
r';(?P<height_pixels>\d+);(?P<width_pixels>\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
Expand Down Expand Up @@ -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'))
Expand Down
14 changes: 7 additions & 7 deletions blessed/sequences.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Module providing 'sequence awareness'."""
from __future__ import annotations

# std imports
import re
import sys
Expand All @@ -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):
Expand All @@ -25,8 +27,6 @@
else:
SupportsIndex = int

_T = TypeVar("_T")

__all__ = ('Sequence', 'SequenceTextWrapper', 'iter_parse', 'measure_length')


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

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

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

Expand Down
2 changes: 1 addition & 1 deletion blessed/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``.

Expand Down
14 changes: 9 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down