Skip to content

FileProxy.isatty() always returns False instead of delegating to the proxied file #4041

@jph00

Description

@jph00

FileProxy (used by Live when redirect_stdout=True) inherits isatty() from io.TextIOBase, which always returns False. This breaks code that checks sys.stdout.isatty() inside a Live context.

FileProxy already delegates fileno() (line 56-57) and has a generic __getattr__ fallback (line 25-26), but isatty() is defined on io.TextIOBase in the MRO, so __getattr__ is never reached for it.

Reproduction

import sys
from rich.console import Console
from rich.live import Live

console = Console()
print("Before Live:", sys.stdout.isatty())  # True

with Live("hello", console=console, redirect_stdout=True):
    print("Inside Live:", sys.stdout.isatty())  # False (should be True)

print("After Live:", sys.stdout.isatty())  # True

Impact

Any code running inside a Live context with redirect_stdout=True that branches on isatty() gets the wrong answer. This is particularly problematic for applications that use Live for streaming display while also executing callbacks/tools that check whether stdout is a terminal.

Suggested fix

Add an isatty() method to FileProxy that delegates to the underlying file, consistent with how fileno() is already handled:

def isatty(self) -> bool:
    return self.__file.isatty()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions