resolved RESOLVED PASS · 10 tool calls · 286 s · Textualize/rich
proxy isatty Fixes https://github.com/Textualize/rich/issues/4041
| # | Tool | Arguments | Result |
|---|---|---|---|
| 1 | run_command | {
"command": "grep -rn \"isatty\" . | head -20"
} | {"status": "ok", "stdout": "./tests/test_null_file.py:9: assert not file.isatty()\n./tests/test_console.py:875: def _mock_isatty():\n./tests/test_console.py:878full{"status": "ok", "stdout": "./tests/test_null_file.py:9: assert not file.isatty()\n./tests/test_console.py:875: def _mock_isatty():\n./tests/test_console.py:878: console.file.isatty = _mock_isatty\n./tests/test_console.py:1079: self.called_isatty = False\n./tests/test_console.py:1081: def isatty(self) -> bool:\n./tests/test_console.py:1082: self.called_isatty = True\n./tests/test_console.py:1086: \"\"\"A file object that reports False for isatty\"\"\"\n./tests/test_console.py:1089: self.called_isatty = False\n./tests/test_console.py:1091: def isatty(self) -> bool:\n./tests/test_console.py:1092: self.called_isatty = True\n./tests/test_console.py:1099: # Should have called isatty to auto-detect tty support\n./tests/test_console.py:1100: assert console.file.called_isatty\n./tests/test_console.py:1107: assert not console.file.called_isatty\n./tests/test_console.py:1114: assert console.file.called_isatty\n./tests/test_console.py:1121: assert console.file.called_isatty\n./tests/test_console.py:1128: assert console.file.called_isatty\n./tests/test_console.py:1135: assert not console.file.called_isatty\n./rich/console.py:969: isatty: Optional[Callable[[], bool]] = getattr(self.file, \"isatty\", None)\n./rich/console.py:971: return False if isatty is None else isatty()\n./rich/console.py:973: # in some situation (at the end of a pytest run for example) isatty() can raise\n", "exit_code": 0} |
| 2 | read_file | {
"filepath": "rich/console.py",
"start_line": 960,
"end_line": 985
} | {"status": "ok", "filepath": "rich/console.py", "content": " if tty_compatible == \"1\":\n return True\n\n # https://force-color.org/\n force_color = environ.gefull{"status": "ok", "filepath": "rich/console.py", "content": " if tty_compatible == \"1\":\n return True\n\n # https://force-color.org/\n force_color = environ.get(\"FORCE_COLOR\")\n if force_color is not None:\n return force_color != \"\"\n\n # Any other value defaults to auto detect\n isatty: Optional[Callable[[], bool]] = getattr(self.file, \"isatty\", None)\n try:\n return False if isatty is None else isatty()\n except ValueError:\n # in some situation (at the end of a pytest run for example) isatty() can raise\n # ValueError: I/O operation on closed file\n # return False because we aren't in a terminal anymore\n return False\n\n @property\n def is_dumb_terminal(self) -> bool:\n \"\"\"Detect dumb terminal.\n\n Returns:\n bool: True if writing to a dumb terminal, otherwise False.\n\n \"\"\"\n", "start_line": 960, "end_line": 985, "total_lines": 2698, "is_truncated": false} |
| 3 | run_command | {
"command": "grep -rn \"FileProxy\" ."
} | {"status": "ok", "stdout": "./CHANGELOG.md:373:- Fixed missing `fileno` on FileProxy\n./CHANGELOG.md:1188:- FileProxy now raises TypeError for empty non-str argfull{"status": "ok", "stdout": "./CHANGELOG.md:373:- Fixed missing `fileno` on FileProxy\n./CHANGELOG.md:1188:- FileProxy now raises TypeError for empty non-str arguments https://github.com/textualize/rich/issues/828\n./tests/test_file_proxy.py:7:from rich.file_proxy import FileProxy\n./tests/test_file_proxy.py:12: file_proxy = FileProxy(console, sys.stdout)\n./tests/test_file_proxy.py:23: file_proxy = FileProxy(console, file)\n./tests/test_file_proxy.py:33: file_proxy = FileProxy(console, file)\n./rich/file_proxy.py:11:class FileProxy(io.TextIOBase):\n./rich/live.py:11:from .file_proxy import FileProxy\n./rich/live.py:198: if self._redirect_stdout and not isinstance(sys.stdout, FileProxy):\n./rich/live.py:200: sys.stdout = cast(\"TextIO\", FileProxy(self.console, sys.stdout))\n./rich/live.py:201: if self._redirect_stderr and not isinstance(sys.stderr, FileProxy):\n./rich/live.py:203: sys.stderr = cast(\"TextIO\", FileProxy(self.console, sys.stderr))\n", "exit_code": 0} |
| 4 | read_file | {
"filepath": "rich/file_proxy.py"
} | {"status": "ok", "filepath": "rich/file_proxy.py", "content": "import io\nfrom typing import IO, TYPE_CHECKING, Any, List\n\nfrom .ansi import AnsiDecoder\nfromfull{"status": "ok", "filepath": "rich/file_proxy.py", "content": "import io\nfrom typing import IO, TYPE_CHECKING, Any, List\n\nfrom .ansi import AnsiDecoder\nfrom .text import Text\n\nif TYPE_CHECKING:\n from .console import Console\n\n\nclass FileProxy(io.TextIOBase):\n \"\"\"Wraps a file (e.g. sys.stdout) and redirects writes to a console.\"\"\"\n\n def __init__(self, console: \"Console\", file: IO[str]) -> None:\n self.__console = console\n self.__file = file\n self.__buffer: List[str] = []\n self.__ansi_decoder = AnsiDecoder()\n\n @property\n def rich_proxied_file(self) -> IO[str]:\n \"\"\"Get proxied file.\"\"\"\n return self.__file\n\n def __getattr__(self, name: str) -> Any:\n return getattr(self.__file, name)\n\n def write(self, text: str) -> int:\n if not isinstance(text, str):\n raise TypeError(f\"write() argument must be str, not {type(text).__name__}\")\n buffer = self.__buffer\n lines: List[str] = []\n while text:\n line, new_line, text = text.partition(\"\\n\")\n if new_line:\n lines.append(\"\".join(buffer) + line)\n buffer.clear()\n else:\n buffer.append(line)\n break\n if lines:\n console = self.__console\n with console:\n output = Text(\"\\n\").join(\n self.__ansi_decoder.decode_line(line) for line in lines\n )\n console.print(output)\n return len(text)\n\n def flush(self) -> None:\n output = \"\".join(self.__buffer)\n if output:\n self.__console.print(output)\n del self.__buffer[:]\n\n def fileno(self) -> int:\n return self.__file.fileno()\n", "start_line": 1, "end_line": 57, "total_lines": 57, "is_truncated": false} |
| 5 | run_command | {
"command": "cat > /tmp/reproduce_isatty.py <<'EOF'\nimport sys\nimport io\nfrom rich.console import Console\nfrom rich.file_proxy import FileProxy\n\nclass MockFile(io.TextIOBase):\n def isatty(self):\n return True\n def write(self, s):\n pass\n def flush(self):\n pass\n\nmock_file = MockFile()\nconsole = Console(file=mock_file)\nproxy = FileProxy(console, mock_file)\nconsole.file = proxy\n\n# Check if isatty is proxied correctly\nprint(f\"Mock file isatty: {mock_file.isatty()}\")\nprint(f\"Proxy isatty: {proxy.isatty()}\")\nEOF\npython3 /tmp/reproduce_isatty.py"
} | {"status": "ok", "stdout": "Mock file isatty: True\nProxy isatty: False\n", "exit_code": 0}full{"status": "ok", "stdout": "Mock file isatty: True\nProxy isatty: False\n", "exit_code": 0} |
| 6 | run_command | {
"command": "python3 -c \"import io; print(dir(io.TextIOBase))\""
} | {"status": "ok", "stdout": "['__abstractmethods__', '__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', full{"status": "ok", "stdout": "['__abstractmethods__', '__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', '__firstlineno__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__next__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__static_attributes__', '__str__', '__subclasshook__', '_abc_impl', '_checkClosed', '_checkReadable', '_checkSeekable', '_checkWritable', 'close', 'closed', 'detach', 'encoding', 'errors', 'fileno', 'flush', 'isatty', 'newlines', 'read', 'readable', 'readline', 'readlines', 'seek', 'seekable', 'tell', 'truncate', 'writable', 'write', 'writelines']\n", "exit_code": 0} |
| 7 | read_file | {
"filepath": "rich/file_proxy.py"
} | {"status": "ok", "filepath": "rich/file_proxy.py", "content": "import io\nfrom typing import IO, TYPE_CHECKING, Any, List\n\nfrom .ansi import AnsiDecoder\nfromfull{"status": "ok", "filepath": "rich/file_proxy.py", "content": "import io\nfrom typing import IO, TYPE_CHECKING, Any, List\n\nfrom .ansi import AnsiDecoder\nfrom .text import Text\n\nif TYPE_CHECKING:\n from .console import Console\n\n\nclass FileProxy(io.TextIOBase):\n \"\"\"Wraps a file (e.g. sys.stdout) and redirects writes to a console.\"\"\"\n\n def __init__(self, console: \"Console\", file: IO[str]) -> None:\n self.__console = console\n self.__file = file\n self.__buffer: List[str] = []\n self.__ansi_decoder = AnsiDecoder()\n\n @property\n def rich_proxied_file(self) -> IO[str]:\n \"\"\"Get proxied file.\"\"\"\n return self.__file\n\n def __getattr__(self, name: str) -> Any:\n return getattr(self.__file, name)\n\n def write(self, text: str) -> int:\n if not isinstance(text, str):\n raise TypeError(f\"write() argument must be str, not {type(text).__name__}\")\n buffer = self.__buffer\n lines: List[str] = []\n while text:\n line, new_line, text = text.partition(\"\\n\")\n if new_line:\n lines.append(\"\".join(buffer) + line)\n buffer.clear()\n else:\n buffer.append(line)\n break\n if lines:\n console = self.__console\n with console:\n output = Text(\"\\n\").join(\n self.__ansi_decoder.decode_line(line) for line in lines\n )\n console.print(output)\n return len(text)\n\n def flush(self) -> None:\n output = \"\".join(self.__buffer)\n if output:\n self.__console.print(output)\n del self.__buffer[:]\n\n def fileno(self) -> int:\n return self.__file.fileno()\n", "start_line": 1, "end_line": 57, "total_lines": 57, "is_truncated": false} |
| 8 | run_command | {
"command": "python3 -c \"import io; print(hasattr(io.TextIOBase, 'isatty'))\""
} | {"status": "ok", "stdout": "True\n", "exit_code": 0}full{"status": "ok", "stdout": "True\n", "exit_code": 0} |
| 9 | edit_file | {
"filepath": "rich/file_proxy.py",
"new_string": " def isatty(self) -> bool:\n return self.__file.isatty()\n\n def fileno(self) -> int:\n return self.__file.fileno()",
"old_string": " def fileno(self) -> int:\n return self.__file.fileno()"
} | {"status": "ok", "filepath": "rich/file_proxy.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/rich/file_proxy.py\n+++ b/rich/file_proxy.py\n@@ -53,5 full{"status": "ok", "filepath": "rich/file_proxy.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/rich/file_proxy.py\n+++ b/rich/file_proxy.py\n@@ -53,5 +53,8 @@\n self.__console.print(output)\n del self.__buffer[:]\n \n+ def isatty(self) -> bool:\n+ return self.__file.isatty()\n+\n def fileno(self) -> int:\n return self.__file.fileno()\n", "is_truncated": false} |
| 10 | run_command | {
"command": "python3 /tmp/reproduce_isatty.py"
} | {"status": "ok", "stdout": "Mock file isatty: True\nProxy isatty: True\n", "exit_code": 0}full{"status": "ok", "stdout": "Mock file isatty: True\nProxy isatty: True\n", "exit_code": 0} |
| 11 | submit_patch | [] | {"status": "ok", "patch_size": 396, "files_changed": 1}full{"status": "ok", "patch_size": 396, "files_changed": 1} |
diff --git a/rich/file_proxy.py b/rich/file_proxy.py
index 4b0b0da6..713926c8 100644
--- a/rich/file_proxy.py
+++ b/rich/file_proxy.py
@@ -53,5 +53,8 @@ class FileProxy(io.TextIOBase):
self.__console.print(output)
del self.__buffer[:]
+ def isatty(self) -> bool:
+ return self.__file.isatty()
+
def fileno(self) -> int:
return self.__file.fileno()
.... [100%] 4 passed in 0.10s