[IPython-User] The completer should not call trait_names

Antony Lee antony.lee@berkeley....
Tue Aug 7 15:38:52 CDT 2012

I understand that the completer tries to get useful attribute names for
Traits objects using the has_traits method, but this can be quite
problematic.  In my case, I have a class with an overriden __getattr__
where obj.foo() results in sending the "foo" instruction on a serial port,
if "foo" does NOT start with an underscore (this allows me to have actual
attributes, prefixed with an "_", as well).  The actual list of valid names
(i.e. valid serial port commands) is actually correctly returned by
dir(obj) as I have overriden __dir__, but ipython's completer still tries
to call trait_names, which sends an invalid command and puts the instrument
at the other end of the serial connection in an error state :-(.  So I had
to special-case the "trait_names" attribute in my __getattr__, but that
feels wrong.
At least, it sounds reasonable that if a __dir__ method is defined then he
who defined it probably knew what he was doing and therefore trait_names
should not be tried?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20120807/3e74513a/attachment.html 

More information about the IPython-User mailing list