Skip to content

Commit

Permalink
Pylint fixes for .pyi files (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
avylove committed Apr 2, 2024
1 parent c28b53f commit e904de3
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 20 deletions.
2 changes: 2 additions & 0 deletions blessed/_capabilities.pyi
@@ -1,3 +1,5 @@
"""Type hint for terminal capability builder patterns"""

# std imports
from typing import Any, Dict, Tuple, OrderedDict

Expand Down
4 changes: 4 additions & 0 deletions blessed/color.pyi
@@ -1,8 +1,12 @@
"""Type hints for color functions"""

# std imports
from typing import Dict, Tuple, Callable

_RGB = Tuple[int, int, int]

# pylint: disable=unused-argument,missing-function-docstring

def rgb_to_xyz(red: int, green: int, blue: int) -> Tuple[float, float, float]: ...
def xyz_to_lab(
x_val: float, y_val: float, z_val: float
Expand Down
4 changes: 4 additions & 0 deletions blessed/colorspace.pyi
@@ -1,8 +1,12 @@
"""Type hints for color reference data"""

# std imports
from typing import Set, Dict, Tuple, NamedTuple

CGA_COLORS: Set[str]

#pylint: disable=missing-class-docstring

class RGBColor(NamedTuple):
red: int
green: int
Expand Down
20 changes: 13 additions & 7 deletions blessed/formatters.pyi
@@ -1,5 +1,8 @@
"""Type hints for sequence-formatting functions"""

# std imports
from typing import (Any,
from typing import (TYPE_CHECKING,
Any,
Set,
List,
Type,
Expand All @@ -11,14 +14,17 @@ from typing import (Any,
Optional,
overload)

# local
from .terminal import Terminal
if TYPE_CHECKING:
# local
from .terminal import Terminal

COLORS: Set[str]
COMPOUNDABLES: Set[str]

_T = TypeVar("_T")

# pylint: disable=unused-argument,missing-function-docstring,missing-class-docstring

class ParameterizingString(str):
def __new__(cls: Type[_T], cap: str, normal: str = ..., name: str = ...) -> _T: ...
@overload
Expand Down Expand Up @@ -58,13 +64,13 @@ class NullCallableString(str):
def __call__(self, *args: str) -> str: ...

def get_proxy_string(
term: Terminal, attr: str
term: 'Terminal', attr: str
) -> Optional[ParameterizingProxyString]: ...
def split_compound(compound: str) -> List[str]: ...
def resolve_capability(term: Terminal, attr: str) -> str: ...
def resolve_capability(term: 'Terminal', attr: str) -> str: ...
def resolve_color(
term: Terminal, color: str
term: 'Terminal', color: str
) -> Union[NullCallableString, FormattingString]: ...
def resolve_attribute(
term: Terminal, attr: str
term: 'Terminal', attr: str
) -> Union[ParameterizingString, FormattingString]: ...
13 changes: 9 additions & 4 deletions blessed/keyboard.pyi
@@ -1,11 +1,16 @@
"""Type hints for 'keyboard awareness'"""

# std imports
from typing import Set, Dict, Type, Mapping, TypeVar, Iterable, Optional, OrderedDict
from typing import TYPE_CHECKING, Set, Dict, Type, Mapping, TypeVar, Iterable, Optional, OrderedDict

# local
from .terminal import Terminal
if TYPE_CHECKING:
# local
from .terminal import Terminal

_T = TypeVar("_T")

# pylint: disable=unused-argument,missing-function-docstring,missing-class-docstring

class Keystroke(str):
def __new__(
cls: Type[_T],
Expand All @@ -21,7 +26,7 @@ class Keystroke(str):
def code(self) -> Optional[int]: ...

def get_keyboard_codes() -> Dict[int, str]: ...
def get_keyboard_sequences(term: Terminal) -> OrderedDict[str, int]: ...
def get_keyboard_sequences(term: 'Terminal') -> OrderedDict[str, int]: ...
def get_leading_prefixes(sequences: Iterable[str]) -> Set[str]: ...
def resolve_sequence(
text: str, mapper: Mapping[str, int], codes: Mapping[int, str]
Expand Down
2 changes: 2 additions & 0 deletions blessed/sequences.py
Expand Up @@ -15,6 +15,8 @@
__all__ = ('Sequence', 'SequenceTextWrapper', 'iter_parse', 'measure_length')


# pylint: disable=unused-argument,missing-function-docstring

class Termcap(object):
"""Terminal capability of given variable name and pattern."""

Expand Down
30 changes: 22 additions & 8 deletions blessed/sequences.pyi
@@ -1,12 +1,26 @@
"""Type hints for 'sequence awareness'"""

# std imports
import textwrap
from typing import Any, Type, Tuple, Pattern, TypeVar, Iterator, Optional, SupportsIndex
from typing import (TYPE_CHECKING,
Any,
Type,
Tuple,
Pattern,
TypeVar,
Iterator,
Optional,
SupportsIndex)

# local
from .terminal import Terminal
if TYPE_CHECKING:
# local
from .terminal import Terminal

_T = TypeVar("_T")

# pylint: disable=unused-argument,missing-function-docstring,missing-class-docstring
# pylint: disable=super-init-not-called

class Termcap:
name: str = ...
pattern: str = ...
Expand All @@ -33,11 +47,11 @@ class Termcap:
) -> "Termcap": ...

class SequenceTextWrapper(textwrap.TextWrapper):
term: Terminal = ...
def __init__(self, width: int, term: Terminal, **kwargs: Any) -> None: ...
term: 'Terminal' = ...
def __init__(self, width: int, term: 'Terminal', **kwargs: Any) -> None: ...

class Sequence(str):
def __new__(cls: Type[_T], sequence_text: str, term: Terminal) -> _T: ...
def __new__(cls: Type[_T], sequence_text: str, term: 'Terminal') -> _T: ...
def ljust(self, width: SupportsIndex, fillchar: str = ...) -> str: ...
def rjust(self, width: SupportsIndex, fillchar: str = ...) -> str: ...
def center(self, width: SupportsIndex, fillchar: str = ...) -> str: ...
Expand All @@ -50,6 +64,6 @@ class Sequence(str):
def padd(self, strip: bool = ...) -> str: ...

def iter_parse(
term: Terminal, text: str
term: 'Terminal', text: str
) -> Iterator[Tuple[str, Optional[Termcap]]]: ...
def measure_length(text: str, term: Terminal) -> int: ...
def measure_length(text: str, term: 'Terminal') -> int: ...
1 change: 1 addition & 0 deletions blessed/terminal.py
Expand Up @@ -894,6 +894,7 @@ def formatter(self, value):
inadvertently returning another terminal capability.
"""
formatters = split_compound(value)
# Pylint sometimes thinks formatters isn't a list # pylint: disable=not-an-iterable
if all((fmt in COLORS or fmt in COMPOUNDABLES) for fmt in formatters):
return getattr(self, value)

Expand Down
8 changes: 7 additions & 1 deletion blessed/terminal.pyi
@@ -1,3 +1,5 @@
"""Type hints for :class:`Terminal`, the primary API entry point."""

# std imports
from typing import IO, Any, List, Tuple, Union, Optional, OrderedDict, SupportsIndex, ContextManager

Expand All @@ -11,6 +13,9 @@ from .formatters import (FormattingString,

HAS_TTY: bool

# pylint: disable=unused-argument,missing-function-docstring,missing-class-docstring
# pylint: disable=too-many-public-methods,too-few-public-methods

class Terminal:
caps: OrderedDict[str, Termcap]
errors: List[str] = ...
Expand Down Expand Up @@ -105,4 +110,5 @@ class Terminal:
self, timeout: Optional[float] = ..., esc_delay: float = ...
) -> Keystroke: ...

class WINSZ: ...
class WINSZ:
...
4 changes: 4 additions & 0 deletions blessed/win_terminal.pyi
@@ -1,9 +1,13 @@
"""Type hints for Windows version of :class:`Terminal`."""

# std imports
from typing import Optional, ContextManager

# local
from .terminal import Terminal as _Terminal

# pylint: disable=missing-class-docstring

class Terminal(_Terminal):
def getch(self) -> str: ...
def kbhit(self, timeout: Optional[float] = ...) -> bool: ...
Expand Down

0 comments on commit e904de3

Please sign in to comment.