1
1
from __future__ import annotations
2
2
3
3
import sys
4
- from typing import TextIO , cast
4
+ from typing import TYPE_CHECKING , TextIO , cast
5
5
6
6
from prompt_toolkit .utils import (
7
7
get_bell_environment_variable ,
13
13
from .color_depth import ColorDepth
14
14
from .plain_text import PlainTextOutput
15
15
16
+ if TYPE_CHECKING :
17
+ from prompt_toolkit .patch_stdout import StdoutProxy
18
+
19
+
16
20
__all__ = [
17
21
"create_output" ,
18
22
]
19
23
20
24
21
25
def create_output (
22
- stdout : TextIO | None = None , always_prefer_tty : bool = False
26
+ stdout : TextIO | StdoutProxy | None = None , always_prefer_tty : bool = False
23
27
) -> Output :
24
28
"""
25
29
Return an :class:`~prompt_toolkit.output.Output` instance for the command
@@ -45,7 +49,7 @@ def create_output(
45
49
if stdout is None :
46
50
# By default, render to stdout. If the output is piped somewhere else,
47
51
# render to stderr.
48
- stdout = sys .__stdout__
52
+ stdout = sys .stdout
49
53
50
54
if always_prefer_tty :
51
55
for io in [sys .stdout , sys .stderr ]:
@@ -57,8 +61,6 @@ def create_output(
57
61
# If the patch_stdout context manager has been used, then sys.stdout is
58
62
# replaced by this proxy. For prompt_toolkit applications, we want to use
59
63
# the real stdout.
60
- from prompt_toolkit .patch_stdout import StdoutProxy
61
-
62
64
while isinstance (stdout , StdoutProxy ):
63
65
stdout = stdout .original_stdout
64
66
0 commit comments