Skip to content

Commit 6b4bd93

Browse files
deathaxesuperbobry
authored andcommitted
Fix typing related imports
This commit ... 1. removes obsolete type imports such as `Dict`, `Optional`, ... . 2. imports as many types as possible in TYPE_CHECKING mode, only to limit impact of typing on runtime import time.
1 parent 61d0c0c commit 6b4bd93

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

pyte/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
"Stream", "ByteStream")
2727

2828
import io
29-
from typing import Union
30-
3129
from .screens import Screen, DiffScreen, HistoryScreen, DebugScreen
3230
from .streams import Stream, ByteStream
3331

pyte/screens.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
import warnings
3636
from collections import deque, defaultdict
3737
from functools import lru_cache
38-
from typing import Any, Dict, List, NamedTuple, Optional, Set, TextIO, TypeVar
39-
from collections.abc import Callable, Generator, Sequence
38+
from typing import TYPE_CHECKING, NamedTuple, TypeVar
4039

4140
from wcwidth import wcwidth as _wcwidth # type: ignore[import-untyped]
4241

@@ -48,6 +47,10 @@
4847
)
4948
from .streams import Stream
5049

50+
if TYPE_CHECKING:
51+
from collections.abc import Callable, Generator, Sequence
52+
from typing import Any, NamedTuple, TextIO
53+
5154
wcwidth: Callable[[str], int] = lru_cache(maxsize=4096)(_wcwidth)
5255

5356
KT = TypeVar("KT")

pyte/streams.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@
2525
import re
2626
import warnings
2727
from collections import defaultdict
28-
from collections.abc import Mapping
29-
from typing import Any, Dict, Optional, TYPE_CHECKING
30-
from collections.abc import Callable, Generator
28+
from typing import TYPE_CHECKING
3129

3230
from . import control as ctrl, escape as esc
3331

3432
if TYPE_CHECKING:
33+
from collections.abc import Callable, Generator, Mapping
34+
from typing import Any
3535
from .screens import Screen
3636

37+
ParserGenerator = Generator[bool | None, str, None]
3738

38-
ParserGenerator = Generator[Optional[bool], str, None]
3939

4040
class Stream:
4141
"""A stream is a state machine that parses a stream of bytes and

0 commit comments

Comments
 (0)