@@ -45,7 +45,7 @@ def create_output(
45
45
if stdout is None :
46
46
# By default, render to stdout. If the output is piped somewhere else,
47
47
# render to stderr.
48
- stdout = sys .stdout
48
+ stdout = sys .__stdout__
49
49
50
50
if always_prefer_tty :
51
51
for io in [sys .stdout , sys .stderr ]:
@@ -54,13 +54,6 @@ def create_output(
54
54
stdout = io
55
55
break
56
56
57
- # If the output is still `None`, use a DummyOutput.
58
- # This happens for instance on Windows, when running the application under
59
- # `pythonw.exe`. In that case, there won't be a terminal Window, and
60
- # stdin/stdout/stderr are `None`.
61
- if stdout is None :
62
- return DummyOutput ()
63
-
64
57
# If the patch_stdout context manager has been used, then sys.stdout is
65
58
# replaced by this proxy. For prompt_toolkit applications, we want to use
66
59
# the real stdout.
@@ -69,6 +62,13 @@ def create_output(
69
62
while isinstance (stdout , StdoutProxy ):
70
63
stdout = stdout .original_stdout
71
64
65
+ # If the output is still `None`, use a DummyOutput.
66
+ # This happens for instance on Windows, when running the application under
67
+ # `pythonw.exe`. In that case, there won't be a terminal Window, and
68
+ # stdin/stdout/stderr are `None`.
69
+ if stdout is None :
70
+ return DummyOutput ()
71
+
72
72
if sys .platform == "win32" :
73
73
from .conemu import ConEmuOutput
74
74
from .win32 import Win32Output
0 commit comments