Skip to content

Commit

Permalink
Merge pull request #3065 from Textualize/fix-ipy
Browse files Browse the repository at this point in the history
Fix iPython breakage
  • Loading branch information
willmcgugan committed Jul 29, 2023
2 parents 236e8e8 + ea1129a commit f16d4be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
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

0 comments on commit f16d4be

Please sign in to comment.