← eval_submission

rich_3882

resolved RESOLVED PASS · 6 tool calls · 25 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 (7)

#ToolArgumentsResult
1run_command
{
 "command": "grep -rn \"PromptBase.on_validate_error\" ."
}
{"status": "error", "error_type": "CommandError", "error_message": "Command failed with exit code 1", "details": {"stdout": "", "stderr": "", "exit_code": 1}}
full
{"status": "error", "error_type": "CommandError", "error_message": "Command failed with exit code 1", "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", "exit_code": 0}
3read_file
{
 "filepath": "rich/prompt.py",
 "start_line": 250,
 "end_line": 270
}
{"status": "ok", "filepath": "rich/prompt.py", "content": " # return the original choice, not the lower case version\n return_value = self.response_type(\n self
full
{"status": "ok", "filepath": "rich/prompt.py", "content": "                # 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", "start_line": 250, "end_line": 270, "total_lines": 400, "is_truncated": false}
4read_file
{
 "end_line": 310,
 "filepath": "rich/prompt.py",
 "start_line": 271
}
{"status": "ok", "filepath": "rich/prompt.py", "content": " def __call__(self, *, stream: Optional[TextIO] = None) -> PromptType:\n ...\n\n @overload\n def __ca
full
{"status": "ok", "filepath": "rich/prompt.py", "content": "    def __call__(self, *, stream: Optional[TextIO] = None) -> PromptType:\n        ...\n\n    @overload\n    def __call__(\n        self, *, default: DefaultType, stream: Optional[TextIO] = None\n    ) -> Union[PromptType, DefaultType]:\n        ...\n\n    def __call__(self, *, default: Any = ..., stream: Optional[TextIO] = None) -> Any:\n        \"\"\"Run the prompt loop.\n\n        Args:\n            default (Any, optional): Optional default value.\n\n        Returns:\n            PromptType: Processed value.\n        \"\"\"\n        while True:\n            self.pre_prompt()\n            prompt = self.make_prompt(default)\n            value = self.get_input(self.console, prompt, self.password, stream=stream)\n            if value == \"\" and default != ...:\n                return default\n            try:\n                return_value = self.process_response(value)\n            except InvalidResponse as error:\n                self.on_validate_error(value, error)\n                continue\n            else:\n                return return_value\n\n\nclass Prompt(PromptBase[str]):\n    \"\"\"A prompt that returns a str.\n\n    Example:\n        >>> name = Prompt.ask(\"Enter your name\")\n\n\n", "start_line": 271, "end_line": 310, "total_lines": 400, "is_truncated": false}
5read_file
{
 "end_line": 265,
 "filepath": "rich/prompt.py",
 "start_line": 255
}
{"status": "ok", "filepath": "rich/prompt.py", "content": " )\n return return_value\n\n def on_validate_error(self, value: str, error: InvalidResponse) -> None:
full
{"status": "ok", "filepath": "rich/prompt.py", "content": "                )\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", "start_line": 255, "end_line": 265, "total_lines": 400, "is_truncated": false}
6edit_file
{
 "filepath": "rich/prompt.py",
 "new_string": "    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, markup=True)",
 "old_string": "    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)"
}
{"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}
7submit_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.17s