Fix pretty printing dispatch #1535

Merged
merged 2 commits into from Apr 15, 2012

Projects

None yet

3 participants

@doerwalter
Contributor

This patch fixes a problem mentioned here:

http://mail.scipy.org/pipermail/ipython-dev/2012-March/008874.html

Search for the best method to use for pretty printing an object now no longer prefers any registered printer in type_printers for the class or any of the base classes over a _repr_pretty_ method defined in the class or any of its base classes.

Instead the mro is walked, looking for both registered printers and _repr_pretty_ methods, so that the inheritance hierarchy will be taken into account.

doerwalter added some commits Mar 30, 2012
@doerwalter doerwalter Fix dispatching in the pretty printing module.
Search for the best method to use for pretty printing an object
now no longer prefers any registered printer in type_printers for
the class or any of the base classes over a _repr_pretty_ method
defined in the class or any of its base classes.

Instead the mro is walked, looking for both registered printers
and _repr_pretty_ methods, so that the inheritance hierarchy will
be taken into account.
63f389b
@doerwalter doerwalter Don't use getattr() when searching for the _repr_pretty_ method.
Using getattr() might find a method in a base class, when a registered
printer for a baseclass later in the mro is the better fit.
bbd672e
@minrk
Member
minrk commented Apr 10, 2012

Looks pretty sound to me. If anyone with more experience here wants to have a peek, please do.

@fperez
Member
fperez commented Apr 15, 2012

Great, thanks @doerwalter for this fix! Sorry it took us a while to review, March and early April were insane for most of the core devs.

Code is clean, with tests; merging now.

@fperez fperez merged commit 81039be into ipython:master Apr 15, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment