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

BUG: Look up the _repr_pretty_ method on the class within the MRO rath... #2123

Merged
merged 1 commit into from
Jul 14, 2012
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions IPython/lib/pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ def pretty(self, obj):
# Some objects automatically create any requested
# attribute. Try to ignore most of them by checking for
# callability.
if '_repr_pretty_' in obj_class.__dict__:
meth = obj_class._repr_pretty_
if '_repr_pretty_' in cls.__dict__:
meth = cls._repr_pretty_
if callable(meth):
return meth(obj, self, cycle)
return _default_pprint(obj, self, cycle)
Expand Down
19 changes: 19 additions & 0 deletions IPython/lib/tests/test_pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def _repr_pretty_(self, p, cycle):
p.text("MyDict(...)")


class Dummy1(object):
def _repr_pretty_(self, p, cycle):
p.text("Dummy1(...)")

class Dummy2(Dummy1):
_repr_pretty_ = None


def test_indentation():
"""Test correct indentation in groups"""
count = 40
Expand All @@ -63,3 +71,14 @@ def test_dispatch():
expectedoutput = "MyDict(...)"

nt.assert_equals(gotoutput, expectedoutput)


def test_callability_checking():
"""
Test that the _repr_pretty_ method is tested for callability and skipped if
not.
"""
gotoutput = pretty.pretty(Dummy2())
expectedoutput = "Dummy1(...)"

nt.assert_equals(gotoutput, expectedoutput)