Skip to content

Commit 52103c8

Browse files
committed
Fix type and import checking
1 parent c4fde87 commit 52103c8

File tree

7 files changed

+32
-12
lines changed

7 files changed

+32
-12
lines changed

prompt_toolkit/contrib/telnet/protocol.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ def ttype(self, data: bytes) -> None:
131131
"""
132132
Received terminal type.
133133
"""
134-
subcmd, ttype = data[0:1], data[1:]
134+
subcmd, data = data[0:1], data[1:]
135135
if subcmd == IS:
136-
ttype = ttype.decode("ascii")
136+
ttype = data.decode("ascii")
137137
self.ttype_received_callback(ttype)
138138
else:
139139
logger.warning("Received a non-IS terminal type Subnegotiation")

prompt_toolkit/contrib/telnet/server.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
NAWS,
2727
SB,
2828
SE,
29+
SEND,
2930
SUPPRESS_GO_AHEAD,
30-
WILL,
3131
TTYPE,
32-
SEND,
32+
WILL,
3333
TelnetProtocolParser,
3434
)
3535

@@ -132,7 +132,6 @@ def __init__(
132132
_initialize_telnet(conn)
133133

134134
# Create input.
135-
self.vt100_output = None
136135
self.vt100_input = create_pipe_input()
137136

138137
# Create output.

prompt_toolkit/input/base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ def close(self) -> None:
9595
pass
9696

9797

98+
class PipeInput(Input):
99+
"""
100+
Abstraction for pipe input.
101+
"""
102+
103+
@abstractmethod
104+
def send_bytes(self, data: bytes) -> None:
105+
"""Feed byte string into the pipe"""
106+
107+
@abstractmethod
108+
def send_text(self, data: str) -> None:
109+
"""Feed a text string into the pipe"""
110+
111+
98112
class DummyInput(Input):
99113
"""
100114
Input for use in a `DummyApplication`

prompt_toolkit/input/defaults.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from prompt_toolkit.utils import is_windows
55

6-
from .base import Input
6+
from .base import Input, PipeInput
77

88
__all__ = [
99
"create_input",
@@ -43,7 +43,7 @@ def create_input(
4343
return Vt100Input(stdin)
4444

4545

46-
def create_pipe_input(responds_to_cpr: bool = True) -> Input:
46+
def create_pipe_input(responds_to_cpr: bool = True) -> PipeInput:
4747
"""
4848
Create an input pipe.
4949
This is mostly useful for unit testing.

prompt_toolkit/input/posix_pipe.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
from typing import ContextManager, TextIO, cast
33

44
from ..utils import DummyContext
5+
from .base import PipeInput
56
from .vt100 import Vt100Input
67

78
__all__ = [
89
"PosixPipeInput",
910
]
1011

1112

12-
class PosixPipeInput(Vt100Input):
13+
class PosixPipeInput(Vt100Input, PipeInput):
1314
"""
1415
Input that is send through a pipe.
1516
This is useful if we want to send the input programmatically into the

prompt_toolkit/input/win32_pipe.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
from ..key_binding import KeyPress
77
from ..utils import DummyContext
8+
from .base import PipeInput
89
from .vt100_parser import Vt100Parser
910
from .win32 import _Win32InputBase, attach_win32_input, detach_win32_input
1011

1112
__all__ = ["Win32PipeInput"]
1213

1314

14-
class Win32PipeInput(_Win32InputBase):
15+
class Win32PipeInput(_Win32InputBase, PipeInput):
1516
"""
1617
This is an input pipe that works on Windows.
1718
Text or bytes can be feed into the pipe, and key strokes can be read from

prompt_toolkit/output/color_depth.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import os
22
from enum import Enum
3-
from typing import Optional
3+
from typing import TYPE_CHECKING, Optional
44

55
from prompt_toolkit.utils import is_dumb_terminal, is_windows
66

7+
if TYPE_CHECKING:
8+
from base import Output
9+
10+
711
__all__ = [
812
"ColorDepth",
913
]
@@ -35,7 +39,7 @@ class ColorDepth(str, Enum):
3539
TRUE_COLOR = DEPTH_24_BIT
3640

3741
@classmethod
38-
def default(cls, output: Optional[Output] = None) -> "ColorDepth":
42+
def default(cls, output: Optional["Output"] = None) -> "ColorDepth":
3943
"""
4044
Return the default color depth, according to the provided output.
4145
@@ -65,7 +69,8 @@ def default(cls, output: Optional[Output] = None) -> "ColorDepth":
6569
# vt100 escape sequences with ENABLE_VIRTUAL_TERMINAL_PROCESSING are
6670
# supported. We don't have a reliable way yet to know whether our
6771
# console supports true color or only 4-bit.
68-
if output.is_windows() and "PROMPT_TOOLKIT_COLOR_DEPTH" not in os.environ:
72+
windows = output.is_windows() if output is not None else is_windows()
73+
if windows and "PROMPT_TOOLKIT_COLOR_DEPTH" not in os.environ:
6974
return cls.DEPTH_4_BIT
7075

7176
# Check the `PROMPT_TOOLKIT_COLOR_DEPTH` environment variable.

0 commit comments

Comments
 (0)