BUG: Fix pretty-printing for overzealous objects #1495

Merged
merged 1 commit into from Mar 16, 2012

Conversation

Projects
None yet
2 participants
Contributor

rkern commented Mar 15, 2012

Some classes use __getattr__ to automatically create requested attributes. The recent trend of LINQ-like query objects is what I ran into. This confuses the pretty-printing machinery that tests for _repr_pretty_. This pull request fixes many of these problems by simply testing if the _repr_pretty_ attribute is callable. This may still be confused by certain mocking frameworks, but it's a good start.

BUG: Fix pretty-printing for overzealous objects that will return som…
…ething non-callable for any requested attribute (thus confusing hasattr).
Owner

minrk commented Mar 15, 2012

Looks clean and sensible to me. Can you name a few libraries that do this sort of thing? Perhaps Pyro, etc. Maybe we can run some extra tests if some of these libraries are present.

Contributor

rkern commented Mar 15, 2012

http://pypi.python.org/pypi/underverse is the one I was using when I ran into the problem.

Owner

minrk commented Mar 16, 2012

We've also had completion issues with these libraries. It would be useful to give a few tests so that future changes will be caught. But for now, I think this can just be merged, unless you want to write a simple test with underverse now.

Contributor

rkern commented Mar 16, 2012

I added a test with a badly-formed _repr_pretty_ attribute. I could write one with a __getattr__ that returns a generator for greater verisimilitude, but I'm not sure what else that would catch that the current test doesn't.

minrk added a commit that referenced this pull request Mar 16, 2012

Merge pull request #1495 from rkern/fix-hyperobject-pprint
BUG: Fix pretty-printing for overzealous objects

Some classes use __getattr__ to automatically create requested attributes. The recent trend of LINQ-like query objects is what I ran into. This confuses the pretty-printing machinery that tests for _repr_pretty_. This pull request fixes many of these problems by simply testing if the _repr_pretty_ attribute is callable. This may still be confused by certain mocking frameworks, but it's a good start.

@minrk minrk merged commit 873e364 into ipython:master Mar 16, 2012

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

Merge pull request #1495 from rkern/fix-hyperobject-pprint
BUG: Fix pretty-printing for overzealous objects

Some classes use __getattr__ to automatically create requested attributes. The recent trend of LINQ-like query objects is what I ran into. This confuses the pretty-printing machinery that tests for _repr_pretty_. This pull request fixes many of these problems by simply testing if the _repr_pretty_ attribute is callable. This may still be confused by certain mocking frameworks, but it's a good start.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment