diff --git a/pyte/__init__.py b/pyte/__init__.py index e004680..35d0a98 100644 --- a/pyte/__init__.py +++ b/pyte/__init__.py @@ -25,14 +25,13 @@ __all__ = ("Screen", "DiffScreen", "HistoryScreen", "DebugScreen", "Stream", "ByteStream") -import io -from typing import Union - from .screens import Screen, DiffScreen, HistoryScreen, DebugScreen from .streams import Stream, ByteStream if __debug__: + import io + def dis(chars: bytes | str) -> None: """A :func:`dis.dis` for terminals. diff --git a/pyte/screens.py b/pyte/screens.py index 7145a7b..384542f 100644 --- a/pyte/screens.py +++ b/pyte/screens.py @@ -35,8 +35,7 @@ import warnings from collections import deque, defaultdict from functools import lru_cache -from typing import Any, Dict, List, NamedTuple, Optional, Set, TextIO, TypeVar -from collections.abc import Callable, Generator, Sequence +from typing import TYPE_CHECKING, NamedTuple, TypeVar from wcwidth import wcwidth as _wcwidth # type: ignore[import-untyped] @@ -48,6 +47,10 @@ ) from .streams import Stream +if TYPE_CHECKING: + from collections.abc import Callable, Generator, Sequence + from typing import Any, NamedTuple, TextIO + wcwidth: Callable[[str], int] = lru_cache(maxsize=4096)(_wcwidth) KT = TypeVar("KT") diff --git a/pyte/streams.py b/pyte/streams.py index 401e814..f728780 100644 --- a/pyte/streams.py +++ b/pyte/streams.py @@ -25,17 +25,17 @@ import re import warnings from collections import defaultdict -from collections.abc import Mapping -from typing import Any, Dict, Optional, TYPE_CHECKING -from collections.abc import Callable, Generator +from typing import TYPE_CHECKING from . import control as ctrl, escape as esc if TYPE_CHECKING: + from collections.abc import Callable, Generator, Mapping + from typing import Any from .screens import Screen + ParserGenerator = Generator[bool | None, str, None] -ParserGenerator = Generator[Optional[bool], str, None] class Stream: """A stream is a state machine that parses a stream of bytes and