Skip to content

Commit

Permalink
Update create_output signature
Browse files Browse the repository at this point in the history
  • Loading branch information
tchalupnik committed Sep 25, 2024
1 parent f43014b commit ad1a312
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/prompt_toolkit/output/defaults.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import sys
from typing import TextIO, cast
from typing import TYPE_CHECKING, TextIO, cast

from prompt_toolkit.utils import (
get_bell_environment_variable,
Expand All @@ -13,13 +13,17 @@
from .color_depth import ColorDepth
from .plain_text import PlainTextOutput

if TYPE_CHECKING:
from prompt_toolkit.patch_stdout import StdoutProxy


__all__ = [
"create_output",
]


def create_output(
stdout: TextIO | None = None, always_prefer_tty: bool = False
stdout: TextIO | StdoutProxy | None = None, always_prefer_tty: bool = False
) -> Output:
"""
Return an :class:`~prompt_toolkit.output.Output` instance for the command
Expand All @@ -45,7 +49,7 @@ def create_output(
if stdout is None:
# By default, render to stdout. If the output is piped somewhere else,
# render to stderr.
stdout = sys.__stdout__
stdout = sys.stdout

if always_prefer_tty:
for io in [sys.stdout, sys.stderr]:
Expand All @@ -57,8 +61,6 @@ def create_output(
# If the patch_stdout context manager has been used, then sys.stdout is
# replaced by this proxy. For prompt_toolkit applications, we want to use
# the real stdout.
from prompt_toolkit.patch_stdout import StdoutProxy

while isinstance(stdout, StdoutProxy):
stdout = stdout.original_stdout

Expand Down

0 comments on commit ad1a312

Please sign in to comment.