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

Already on GitHub? Sign in to your account

Fix pretty print of types when `__module__` is not available. #2685

Merged
merged 2 commits into from Dec 16, 2012

Conversation

Projects
None yet
2 participants
Contributor

bfroehle commented Dec 15, 2012

In Python 3, heap allocated types -- for example those created using
PyType_FromSpec -- lack the __module__ attribute.

Closes #2684

@bfroehle bfroehle Fix pretty print of types when `__module__` is not available.
In Python 3, heap allocated types -- for example those created using
PyType_FromSpec -- lack the `__module__` attribute.

Closes #2684
9b11523

@takluyver takluyver commented on the diff Dec 15, 2012

IPython/lib/pretty.py
@@ -604,10 +604,16 @@ def _re_pattern_pprint(obj, p, cycle):
def _type_pprint(obj, p, cycle):
"""The pprint for classes and types."""
- if obj.__module__ in ('__builtin__', 'exceptions'):
+ try:
+ mod = obj.__module__
+ except AttributeError:
+ # Heap allocated types might not have the module attribute.
+ return p.text(obj.__name__)
@takluyver

takluyver Dec 15, 2012

Owner

There's no way __name__ could be missing too, I hope?

@bfroehle

bfroehle Dec 16, 2012

Contributor

No, I went and read the C source -- name will always be defined.

Owner

takluyver commented Dec 16, 2012

Great, looks good to me, then. Could we also add a simple tests? It can be conditional on xxlimited being importable, assuming that's widely available (I've got it on my Python 3 installations).

Contributor

bfroehle commented Dec 16, 2012

Okay, added a test. I think it was skipped on Travis py32 test, but it runs for me locally.

Owner

takluyver commented Dec 16, 2012

Great, thanks. I'll land this, then.

@takluyver takluyver added a commit that referenced this pull request Dec 16, 2012

@takluyver takluyver Merge pull request #2685 from bfroehle/pretty_print_heap_type
Fix pretty print of types when `__module__` is not available.
bb2d35b

@takluyver takluyver merged commit bb2d35b into ipython:master Dec 16, 2012

1 check passed

default The Travis build passed
Details

@minrk minrk added a commit that referenced this pull request Mar 5, 2013

@minrk minrk Backport PR #2685: Fix pretty print of types when `__module__` is not…
… available.

In Python 3, heap allocated types -- for example those created using
PyType_FromSpec -- lack the `__module__` attribute.

Closes #2684
2c82919

@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014

@takluyver takluyver Merge pull request #2685 from bfroehle/pretty_print_heap_type
Fix pretty print of types when `__module__` is not available.
36719ad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment