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

allow class.__module__ to be None #3377

Merged
merged 2 commits into from
May 29, 2013
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
8 changes: 4 additions & 4 deletions IPython/lib/pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,10 +638,10 @@ def _re_pattern_pprint(obj, p, cycle):

def _type_pprint(obj, p, cycle):
"""The pprint for classes and types."""
try:
mod = obj.__module__
except AttributeError:
# Heap allocated types might not have the module attribute.
mod = getattr(obj, '__module__', None)
if mod is None:
# Heap allocated types might not have the module attribute,
# and others may set it to None.
return p.text(obj.__name__)

if mod in ('__builtin__', 'exceptions'):
Expand Down
12 changes: 12 additions & 0 deletions IPython/lib/tests/test_pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ def _repr_pretty_(self, p, cycle):
class Dummy2(Dummy1):
_repr_pretty_ = None

class NoModule(object):
pass

NoModule.__module__ = None


def test_indentation():
"""Test correct indentation in groups"""
Expand Down Expand Up @@ -106,3 +111,10 @@ def test_pprint_heap_allocated_type():
import xxlimited
output = pretty.pretty(xxlimited.Null)
nt.assert_equal(output, 'xxlimited.Null')

def test_pprint_nomod():
"""
Test that pprint works for classes with no __module__.
"""
output = pretty.pretty(NoModule)
nt.assert_equal(output, 'NoModule')