Uniform Function Call Syntax (UFCS)

Chris Angelico rosuav at gmail.com
Mon Jun 9 00:53:37 EDT 2014


On Mon, Jun 9, 2014 at 1:53 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
>> which means that hasattr (which is defined by
>> attempting to get the attribute and seeing if an exception is thrown)
>> has to return True.
>
> Yes. And this is a problem why?
>
> Obviously it would mean that the semantics of hasattr will be different
> than they are now, but it's still a coherent set of semantics.

Coherent perhaps, but in direct opposition to the OP's statement about
how hasattr should return False even if there's a global to be found.

A coherent meaning for this kind of thing would almost certainly not
be possible within the OP's requirements, although it's entirely
possible something sensible could be put together.

(By the way, would (3).squared return a curried reference to squared
as of when you looked it up, or would it return something that
late-binds to whatever 'squared' is in scope as of when you call it?
If the latter, then hasattr would have to always return True, and
getattr would have to return something that does the late-bind lookup
and turns NameError into AttributeError.)

ChrisA



More information about the Python-list mailing list