Skip to content

Commit

Permalink
Use guard when importing Terminal in .pyi files
Browse files Browse the repository at this point in the history
  • Loading branch information
avylove committed Apr 1, 2024
1 parent b432f7c commit 8c36af6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
16 changes: 9 additions & 7 deletions blessed/formatters.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +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 @@ -13,8 +14,9 @@ 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]
Expand Down Expand Up @@ -62,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]: ...
9 changes: 5 additions & 4 deletions blessed/keyboard.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""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")

Expand All @@ -25,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
25 changes: 17 additions & 8 deletions blessed/sequences.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

# 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")

Expand Down Expand Up @@ -38,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 @@ -55,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: 0 additions & 1 deletion blessed/terminal.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import IO, Any, List, Tuple, Union, Optional, OrderedDict, SupportsIndex, ContextManager

# local
# The type hints do have circular imports, but the code doesn't # pylint: disable=cyclic-import
from .keyboard import Keystroke
from .sequences import Termcap
from .formatters import (FormattingString,
Expand Down

0 comments on commit 8c36af6

Please sign in to comment.