failed WRONG_FIX UNSUBMITTED wrong_fix_unsubmitted(None) · None tool calls · 0 s · Textualize/rich
(not found in data/tasks.jsonl)
| # | Tool | Arguments | Result |
|---|---|---|---|
| No trace captured. | |||
--- a/rich/pretty.py
+++ b/rich/pretty.py
@@ -55,13 +55,6 @@ if TYPE_CHECKING:
)
-JUPYTER_CLASSES_TO_NOT_RENDER = {
- # Matplotlib "Artists" manage their own rendering in a Jupyter notebook, and we should not try to render them too.
- # "Typically, all [Matplotlib] visible elements in a figure are subclasses of Artist."
- "matplotlib.artist.Artist",
-}
-
-
def _is_attr_object(obj: Any) -> bool:
"""Check if an object was created with attrs module."""
return _has_attrs and _attr_module.has(type(obj))
@@ -122,69 +115,40 @@ def _ipy_display_hook(
max_string: Optional[int] = None,
max_depth: Optional[int] = None,
expand_all: bool = False,
-) -> None:
+) -> Union[str, None]:
# needed here to prevent circular import:
- from ._inspect import is_object_one_of_types
from .console import ConsoleRenderable
# always skip rich generated jupyter renderables or None values
if _safe_isinstance(value, JupyterRenderable) or value is None:
- return
+ return None
console = console or get_console()
- if console.is_jupyter:
- # Delegate rendering to IPython if the object (and IPython) supports it
- # https://ipython.readthedocs.io/en/stable/config/integrating.html#rich-display
- ipython_repr_methods = [
- "_repr_html_",
- "_repr_markdown_",
- "_repr_json_",
- "_repr_latex_",
- "_repr_jpeg_",
- "_repr_png_",
- "_repr_svg_",
- "_repr_mimebundle_",
- ]
- for repr_method in ipython_repr_methods:
- method = getattr(value, repr_method, None)
- if inspect.ismethod(method):
- # Calling the method ourselves isn't ideal. The interface for the `_repr_*_` methods
- # specifies that if they return None, then they should not be rendered
- # by the notebook.
- try:
- repr_result = method()
- except Exception:
- continue # If the method raises, treat it as if it doesn't exist, try any others
- if repr_result is not None:
- return # Delegate rendering to IPython
-
- # When in a Jupyter notebook let's avoid the display of some specific classes,
- # as they result in the rendering of useless and noisy lines such as `<Figure size 432x288 with 1 Axes>`.
- # What does this do?
- # --> if the class has "matplotlib.artist.Artist" in its hierarchy for example, we don't render it.
- if is_object_one_of_types(value, JUPYTER_CLASSES_TO_NOT_RENDER):
- return
-
- # certain renderables should start on a new line
- if _safe_isinstance(value, ConsoleRenderable):
- console.line()
-
- console.print(
- value
- if _safe_isinstance(value, RichRenderable)
- else Pretty(
- value,
- overflow=overflow,
- indent_guides=indent_guides,
- max_length=max_length,
- max_string=max_string,
- max_depth=max_depth,
- expand_all=expand_all,
- margin=12,
- ),
- crop=crop,
- new_line_start=True,
- )
+
+ with console.capture() as capture:
+ # certain renderables should start on a new line
+ if _safe_isinstance(value, ConsoleRenderable):
+ console.line()
+ console.print(
+ value
+ if _safe_isinstance(value, RichRenderable)
+ else Pretty(
+ value,
+ overflow=overflow,
+ indent_guides=indent_guides,
+ max_length=max_length,
+ max_string=max_string,
+ max_depth=max_depth,
+ expand_all=expand_all,
+ margin=12,
+ ),
+ crop=crop,
+ new_line_start=True,
+ end="",
+ )
+ # strip trailing newline, not usually part of a text repr
+ # I'm not sure if this should be prevented at a lower level
+ return capture.get().rstrip("\n")
def _safe_isinstance(
........F
=================================== FAILURES ===================================
____________________________ test_pretty_dataclass _____________________________
def test_pretty_dataclass():
dc = ExampleDataclass(1000, "Hello, World", 999, ["foo", "bar", "baz"])
result = pretty_repr(dc, max_width=80)
print(repr(result))
assert (
result
== "ExampleDataclass(foo=1000, bar='Hello, World', baz=['foo', 'bar', 'baz'])"
)
result = pretty_repr(dc, max_width=16)
print(repr(result))
> assert (
result
== "ExampleDataclass(\n foo=1000,\n bar='Hello, World',\n baz=[\n 'foo',\n 'bar',\n 'baz'\n ]\n)"
)
E assert "ExampleDatac...bar', 'baz'])" == "ExampleDatac...az'\n ]\n)"
E
E + ExampleDataclass(foo=1000, bar='Hello, World', baz=['foo', 'bar', 'baz'])
E - ExampleDataclass(
E - foo=1000,
E - bar='Hello, World',
E - baz=[
E - 'foo',...
E
E ...Full output truncated (4 lines hidden), use '-vv' to show
tests/test_pretty.py:176: AssertionError
----------------------------- Captured stdout call -----------------------------
"ExampleDataclass(foo=1000, bar='Hello, World', baz=['foo', 'bar', 'baz'])"
"ExampleDataclass(foo=1000, bar='Hello, World', baz=['foo', 'bar', 'baz'])"
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 failed, 8 passed in 0.14s