← eval_submission_analyzer

rich_3882

resolved RESOLVED PASS · 7 tool calls · 41 s · Textualize/rich

Task input

Fix raw markup printed on prompt errors sometimes

## Type of changes

- [x] Bug fix
- [ ] New feature
- [ ] Documentation / docstrings
- [ ] Tests
- [ ] Other

## Checklist

- [x] I've run the latest [black](https://github.com/psf/black) with default args on new code.
- [ ] I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate (see note about typos above).
- [x] I've added tests for new code.
- [x] I accept that @willmcgugan may be pedantic in the code review.

## Description

PromptBase.on_validate_error() should explicitly ask for markup in case the console passed to it has markup disabled globally.

Fixes #3881.

Tool calls (8)

#ToolArgumentsResult
1run_command
{
 "command": "grep -rn \"on_validate_error\" /workspace | grep \"PromptBase\""
}
{"status": "error", "error_type": "CommandError", "error_message": "Command failed with exit code 1", "details": {"stdout": "", "stderr": "grep: /tmp/swe_work/e
full
{"status": "error", "error_type": "CommandError", "error_message": "Command failed with exit code 1", "details": {"stdout": "", "stderr": "grep: /tmp/swe_work/eval_submission_analyzer/rich_3882/a/workspace: No such file or directory\n", "exit_code": 1}}
2run_command
{
 "command": "find . -maxdepth 4 -name \"*prompt*\""
}
{"status": "ok", "stdout": "./tests/test_prompt.py\n./docs/source/reference/prompt.rst\n./docs/source/prompt.rst\n./rich/prompt.py\n", "exit_code": 0}
full
{"status": "ok", "stdout": "./tests/test_prompt.py\n./docs/source/reference/prompt.rst\n./docs/source/prompt.rst\n./rich/prompt.py\n", "exit_code": 0}
3run_command
{
 "command": "grep -n \"def on_validate_error\" rich/prompt.py"
}
{"status": "ok", "stdout": "258: def on_validate_error(self, value: str, error: InvalidResponse) -> None:\n", "exit_code": 0}
full
{"status": "ok", "stdout": "258:    def on_validate_error(self, value: str, error: InvalidResponse) -> None:\n", "exit_code": 0}
4read_file
{
 "end_line": 270,
 "filepath": "rich/prompt.py",
 "start_line": 258
}
{"status": "ok", "filepath": "rich/prompt.py", "content": " def on_validate_error(self, value: str, error: InvalidResponse) -> None:\n \"\"\"Called to handle va
full
{"status": "ok", "filepath": "rich/prompt.py", "content": "    def on_validate_error(self, value: str, error: InvalidResponse) -> None:\n        \"\"\"Called to handle validation error.\n\n        Args:\n            value (str): String entered by user.\n            error (InvalidResponse): Exception instance the initiated the error.\n        \"\"\"\n        self.console.print(error)\n\n    def pre_prompt(self) -> None:\n        \"\"\"Hook to display something before the prompt.\"\"\"\n\n    @overload\n", "start_line": 258, "end_line": 270, "total_lines": 400, "is_truncated": false}
5read_file
{
 "end_line": 266,
 "filepath": "rich/prompt.py",
 "start_line": 258
}
{"status": "ok", "filepath": "rich/prompt.py", "content": " def on_validate_error(self, value: str, error: InvalidResponse) -> None:\n \"\"\"Called to handle va
full
{"status": "ok", "filepath": "rich/prompt.py", "content": "    def on_validate_error(self, value: str, error: InvalidResponse) -> None:\n        \"\"\"Called to handle validation error.\n\n        Args:\n            value (str): String entered by user.\n            error (InvalidResponse): Exception instance the initiated the error.\n        \"\"\"\n        self.console.print(error)\n\n", "start_line": 258, "end_line": 266, "total_lines": 400, "is_truncated": false}
6edit_file
{
 "filepath": "rich/prompt.py",
 "new_string": "        self.console.print(error, markup=True)",
 "old_string": "        self.console.print(error)"
}
{"status": "ok", "filepath": "rich/prompt.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/rich/prompt.py\n+++ b/rich/prompt.py\n@@ -262,7 +262,7 @@\n
full
{"status": "ok", "filepath": "rich/prompt.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/rich/prompt.py\n+++ b/rich/prompt.py\n@@ -262,7 +262,7 @@\n             value (str): String entered by user.\n             error (InvalidResponse): Exception instance the initiated the error.\n         \"\"\"\n-        self.console.print(error)\n+        self.console.print(error, markup=True)\n \n     def pre_prompt(self) -> None:\n         \"\"\"Hook to display something before the prompt.\"\"\"\n", "is_truncated": false}
7run_command
{
 "command": "python3 -c \"from rich.console import Console; from rich.prompt import Prompt; from rich.prompt import InvalidResponse; \n\nclass MyPrompt(Prompt):\n    def validate(self, value: str) -> str:\n        if value != 'yes':\n            raise InvalidResponse('[red]Invalid response![/red]')\n        return value\n\nconsole = Console(markup=False)\nprompt = MyPrompt(console=console)\n\n# We need to mock the input and capture the output\nimport io\nfrom contextlib import redirect_stdout\n\nf = io.StringIO()\nwith redirect_stdout(f):\n    try:\n        # Mocking input to trigger validation error\n        import builtins\n        original_input = builtins.input\n        builtins.input = lambda _: 'no'\n        prompt.ask('Test')\n        builtins.input = original_input\n    except Exception:\n        pass\n\noutput = f.getvalue()\nprint(f'Output: {output}')\n# If markup=True worked, the output should contain ANSI escape codes for red, \n# even though console.markup=False.\n# If it didn't, it would contain '[red]Invalid response![/red]'\nif '[red]' in output:\n    print('FAILED: Markup was printed as raw text')\nelse:\n    print('SUCCESS: Markup was processed')\n\""
}
{"status": "ok", "stdout": "Output: Test: \nSUCCESS: Markup was processed\n", "exit_code": 0}
full
{"status": "ok", "stdout": "Output: Test: \nSUCCESS: Markup was processed\n", "exit_code": 0}
8submit_patch
[]
{"status": "ok", "patch_size": 503, "files_changed": 1}
full
{"status": "ok", "patch_size": 503, "files_changed": 1}

Patch

diff --git a/rich/prompt.py b/rich/prompt.py
index c7cf25ba..ae94d9bb 100644
--- a/rich/prompt.py
+++ b/rich/prompt.py
@@ -262,7 +262,7 @@ class PromptBase(Generic[PromptType]):
             value (str): String entered by user.
             error (InvalidResponse): Exception instance the initiated the error.
         """
-        self.console.print(error)
+        self.console.print(error, markup=True)
 
     def pre_prompt(self) -> None:
         """Hook to display something before the prompt."""

Test output

show
........                                                                 [100%]
8 passed in 0.15s