Uniform Function Call Syntax (UFCS)

Ian Kelly ian.g.kelly at gmail.com
Sun Jun 8 13:24:28 EDT 2014


On Sun, Jun 8, 2014 at 11:13 AM, Chris Angelico <rosuav at gmail.com> wrote:
> On Mon, Jun 9, 2014 at 3:08 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
>> On Sun, Jun 8, 2014 at 10:48 AM, Chris Angelico <rosuav at gmail.com> wrote:
>>> Except that it's even more complicated than that, because hasattr
>>> wasn't defined in your module, so it has a different set of globals.
>>> In fact, this would mean that hasattr would become quite useless.
>>
>> hasattr is a builtin, so it has no globals at all.  It would have to
>> use the calling scope for UFCS resolution as in my example
>> implementation.
>
> Same difference. It can't simply look for the name in globals(), it
> has to figure out based on the caller's globals.

But that would all be done in getattr, so I don't think it affects
hasattr's implementation at all.  Since hasattr doesn't push anything
onto the stack, getattr doesn't have to care whether it was called
directly from Python or indirectly via getattr; either way the scope
it needs is just the top frame of the stack.

Could be a different matter in other implementations, though.



More information about the Python-list mailing list