Ticket #229 (assigned defect)

Opened 8 months ago

Last modified 8 months ago

don't call object.trait_names() on arbitrary user objects

Reported by: dimaqq Assigned to: vivainio (accepted)
Priority: high Milestone:
Component: ipython Version:
Severity: normal Keywords:
Cc:

Description

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

Change History

02/20/08 15:46:52 changed by vivainio

  • status changed from new to assigned.
  • owner changed from fperez to vivainio.

02/20/08 15:49:18 changed by vivainio

Would it be ok for other devs if I made this an rc options, e.g. you'd have to do

ip.options.find_special_attributes = True

(the name is up for discussion)

to attempt finding methods with these attributes?

The option would be disabled as a default, but I'd add it to ipy_user_conf.py, commented out & with explanation.

02/20/08 16:29:45 changed by vivainio

  • priority changed from normal to high.