Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix iPython breakage #3065

Merged
merged 1 commit into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed exception in Markdown with partial table https://github.com/Textualize/rich/issues/3053
- Fixed the HTML export template so that the `<html>` tag comes before the `<head>` tag https://github.com/Textualize/rich/issues/3021
- Fixed issue with custom classes overwriting `__eq__` https://github.com/Textualize/rich/issues/2875
- Fix rich.pretty.install breakage in iPython https://github.com/Textualize/rich/issues/3013

### Added

Expand Down
13 changes: 7 additions & 6 deletions rich/pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,11 @@ def display_hook(value: Any) -> None:
)
builtins._ = value # type: ignore[attr-defined]

if "get_ipython" in globals():
try:
ip = get_ipython() # type: ignore[name-defined]
except NameError:
sys.displayhook = display_hook
else:
from IPython.core.formatters import BaseFormatter

class RichFormatter(BaseFormatter): # type: ignore[misc]
Expand All @@ -236,8 +239,6 @@ def __call__(self, value: Any) -> Any:
# replace plain text formatter with rich formatter
rich_formatter = RichFormatter()
ip.display_formatter.formatters["text/plain"] = rich_formatter
else:
sys.displayhook = display_hook


class Pretty(JupyterMixin):
Expand Down Expand Up @@ -708,9 +709,9 @@ def iter_rich_args(rich_args: Any) -> Iterable[Union[Any, Tuple[str, Any]]]:
last=root,
)

def iter_attrs() -> Iterable[
Tuple[str, Any, Optional[Callable[[Any], str]]]
]:
def iter_attrs() -> (
Iterable[Tuple[str, Any, Optional[Callable[[Any], str]]]]
):
"""Iterate over attr fields and values."""
for attr in attr_fields:
if attr.repr:
Expand Down
Loading