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

Using hasattr for trait_names instead of just looking for it directly/using __dir__? #4381

Closed
jtratner opened this issue Oct 11, 2013 · 5 comments · Fixed by #4382
Closed
Milestone

Comments

@jtratner
Copy link
Contributor

This issue just came up with IPython 2.0-dev (appears to not be an issue for IPython 1.0) where our DictWrapper object raised KeyError on bad __getattr__ (which screws up hasattr). It's a badly behaved object, but it's been around for a while. We're going to fix this in 0.13, which we're releasing soonish, but this probably affects a number of versions. pandas-dev/pandas#5182

I'm not clear why defining a __dir__ method isn't enough, but a simple fix would be to go the EAFP route and just try to do it in try/except rather than doing the hasattr check. I'm sure there are other places where this could be an issue

cc @d10genes who pointed out the problematic interaction with IPython 2.0-dev.

@jtratner
Copy link
Contributor Author

For clarity - I bring this up because I wanted to point out that objects misbehave and it's probably surprising to users; however, but it's not unreasonable to think that most things should work right with hasattr ;p

@takluyver
Copy link
Member

We have a safe_hasattr() function in IPython.core.oinspect which can be used for this.

@jtratner
Copy link
Contributor Author

okay, I can put up a fix for this if you want...

@takluyver
Copy link
Member

Sure. The function should probably be moved into utils somewhere, because stuff in utils shouldn't rely on things in core.

@jtratner
Copy link
Contributor Author

So just move from oinspect and then add an import from utils?

@minrk minrk added this to the 2.0 milestone Mar 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants