A proposal for attribute lookup failures

Arnaud Delobelle arnodel at googlemail.com
Sun Nov 18 07:42:13 EST 2007


On Nov 18, 4:07 am, MonkeeSage <MonkeeS... at gmail.com> wrote:
> Proposal:
>
>   When an attribute lookup fails for an object, check the top-level
> (and local scope?) for a corresponding function or attribute and apply
> it as the called attribute if found, drop through to the exception
> otherwise. This is just syntactic sugar.

[...]

> Benefits:

[...]

>   - Backwards compatible; one can use the top-level functions when
> desired. No change to existing code required.

It changes how the following code executes:

--------------------------
def foo(x): return x.foo()
foo(1)
--------------------------

* currently this raises AttributeError
* under your proposal this code would fill the stack and raise a
RuntimeError I guess.

>   - Seemingly trivial to implement (though I don't know much C). On
> attribute lookup failure, simply iterate the symbol table looking for
> a match, otherwise raise the exception (like current implementation).

This is not a benefit!


--
Arnaud




More information about the Python-list mailing list