[Ipython-tickets] [IPython] #229: don't call object.trait_names() on arbitrary user objects

IPython ipython-tickets@scipy....
Fri Feb 15 02:56:50 CST 2008


#229: don't call object.trait_names() on arbitrary user objects
---------------------+------------------------------------------------------
 Reporter:  dimaqq   |       Owner:  fperez
     Type:  defect   |      Status:  new   
 Priority:  normal   |   Milestone:        
Component:  ipython  |     Version:        
 Severity:  normal   |    Keywords:        
---------------------+------------------------------------------------------
 Currently for every class that defines {{{__getattr__}}} to retrun a
 callable, I have to define these to work around ipython: {{{__repr__,
 _getAttributeNames, __methods__, trait_names}}}.

 First three could be worked around by disallowing underscore names in
 {{{__getattr__}}}, but there's hardly any generic logic that could exclude
 trait_names.

 I think that if ipython thinks my object might be trait-able (whatever
 that is) it should first interrogate some underscore method or type or
 something else.

 In any event ipython cannot arbitratily call an innocently named method
 like {{{trait_names()}}} because ipython doesn't know what side effects
 that might cause.


 Example:
 {{{
 # usage:
 # server = rpc_caller("http://....")
 # rv = server.get_customer_info(arg1, arg2, ...)

 class rpc_caller:
   def __init__(self, base):
     self.base = base

   def __getattr__(self, name):
     return lambda *args, **kwargs: do_rpc_call(self.base, name, args,
 kwargs)

 # initialize some caller
 rpc = rpc_caller("http://...")
 }}}

 after this, tab-expansion in ipython results in aweful side-effects,
 because ipython eventually calls {{{rpc.trait_names()}}} which the system
 is completely unprepared for.

 also {{{globals()}}} may fail with exception

 another case where this caused a serious bug for me was when
 {{{__getattr__}}} returned a gtk widget

 last checked against ipython 0.8.1

-- 
Ticket URL: <http://ipython.scipy.org/ipython/ipython/ticket/229>
IPython <http://ipython.scipy.org>
The IPython interactive Python system


More information about the Ipython-tickets mailing list