← eval8_submission_v1l

rich_3882

resolved RESOLVED PASS · 12 tool calls · 94 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 (13)

#ToolArgumentsResult
1run_command
{
 "command": "grep -rn \"PromptBase\" . | grep \"on_validate_error\""
}
{"status": "error", "error_type": "CommandError", "error_message": "", "details": {"stdout": "", "stderr": "", "exit_code": 1}}
full
{"status": "error", "error_type": "CommandError", "error_message": "", "details": {"stdout": "", "stderr": "", "exit_code": 1}}
2run_command
{
 "command": "grep -rn \"on_validate_error\" ."
}
{"status": "ok", "stdout": "./rich/prompt.py:258: def on_validate_error(self, value: str, error: InvalidResponse) -> None:\n./rich/prompt.py:298: self.on_valida
full
{"status": "ok", "stdout": "./rich/prompt.py:258:    def on_validate_error(self, value: str, error: InvalidResponse) -> None:\n./rich/prompt.py:298:                self.on_validate_error(value, error)\n", "stderr": "", "exit_code": 0}
3run_command
{
 "command": "sed -n '250,270p' rich/prompt.py"
}
{"status": "ok", "stdout": " # return the original choice, not the lower case version\n return_value = self.response_type(\n self.choices[\n [choice.lower() for
full
{"status": "ok", "stdout": "                # return the original choice, not the lower case version\n                return_value = self.response_type(\n                    self.choices[\n                        [choice.lower() for choice in self.choices].index(value.lower())\n                    ]\n                )\n        return return_value\n\n    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", "stderr": "", "exit_code": 0}
4run_command
{
 "command": "grep -n \"class Prompt\" rich/prompt.py"
}
{"status": "ok", "stdout": "11:class PromptError(Exception):\n30:class PromptBase(Generic[PromptType]):\n304:class Prompt(PromptBase[str]):\n", "stderr": "", "e
full
{"status": "ok", "stdout": "11:class PromptError(Exception):\n30:class PromptBase(Generic[PromptType]):\n304:class Prompt(PromptBase[str]):\n", "stderr": "", "exit_code": 0}
5run_command
{
 "command": "sed -n '258,265p' rich/prompt.py"
}
{"status": "ok", "stdout": " def on_validate_error(self, value: str, error: InvalidResponse) -> None:\n \"\"\"Called to handle validation error.\n\n Args:\n val
full
{"status": "ok", "stdout": "    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", "stderr": "", "exit_code": 0}
6run_command
{
 "command": "python3 -c \"from rich.console import Console; from rich.prompt import Prompt; from rich.errors import InvalidResponse; console = Console(markup=False); p = Prompt(console=console); p.on_validate_error('val', InvalidResponse('[red]Error[/red]'));\""
}
{"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n File \"<string>\", line 1, in <module>\n from rich.cons
full
{"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\n    from rich.console import Console; from rich.prompt import Prompt; from rich.errors import InvalidResponse; console = Console(markup=False); p = Prompt(console=console); p.on_validate_error('val', InvalidResponse('[red]Error[/red]'));\n                                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nImportError: cannot import name 'InvalidResponse' from 'rich.errors' (/workspace/rich/errors.py)\n", "details": {"stdout": "", "stderr": "Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\n    from rich.console import Console; from rich.prompt import Prompt; from rich.errors import InvalidResponse; console = Console(markup=False); p = Prompt(console=console); p.on_validate_error('val', InvalidResponse('[red]Error[/red]'));\n                                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nImportError: cannot import name 'InvalidResponse' from 'rich.errors' (/workspace/rich/errors.py)\n", "exit_code": 1}}
7run_command
{
 "command": "grep -n \"InvalidResponse\" rich/prompt.py"
}
{"status": "ok", "stdout": "15:class InvalidResponse(PromptError):\n234: InvalidResponse: If ``value`` is invalid.\n243: raise InvalidResponse(self.validate_err
full
{"status": "ok", "stdout": "15:class InvalidResponse(PromptError):\n234:            InvalidResponse: If ``value`` is invalid.\n243:            raise InvalidResponse(self.validate_error_message)\n247:                raise InvalidResponse(self.illegal_choice_message)\n258:    def on_validate_error(self, value: str, error: InvalidResponse) -> None:\n263:            error (InvalidResponse): Exception instance the initiated the error.\n297:            except InvalidResponse as error:\n362:            raise InvalidResponse(self.validate_error_message)\n", "stderr": "", "exit_code": 0}
8run_command
{
 "command": "python3 -c \"from rich.console import Console; from rich.prompt import Prompt, InvalidResponse; console = Console(markup=False); p = Prompt(console=console); p.on_validate_error('val', InvalidResponse('[red]Error[/red]'));\""
}
{"status": "ok", "stdout": "[red]Error[/red]\n", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "[red]Error[/red]\n", "stderr": "", "exit_code": 0}
9edit_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}
10run_command
{
 "command": "python3 -c \"from rich.console import Console; from rich.prompt import Prompt, InvalidResponse; console = Console(markup=False); p = Prompt(console=console); p.on_validate_error('val', InvalidResponse('[red]Error[/red]'));\""
}
{"status": "ok", "stdout": "Error\n", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "Error\n", "stderr": "", "exit_code": 0}
11run_command
{
 "command": "cd /workspace && git status --short && git diff --stat"
}
{"status": "ok", "stdout": " M rich/prompt.py\n rich/prompt.py | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": " M rich/prompt.py\n rich/prompt.py | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n", "stderr": "", "exit_code": 0}
12run_command
{
 "command": "python3 -c \"from rich.console import Console; from rich.prompt import Prompt, InvalidResponse; console = Console(markup=False); p = Prompt(console=console); p.on_validate_error('val', InvalidResponse('[red]Error[/red]'));\""
}
{"status": "ok", "stdout": "Error\n", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "Error\n", "stderr": "", "exit_code": 0}
13submit_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.16s