Uniform Function Call Syntax (UFCS)
jongiddy
jongiddy at gmail.com
Sun Jun 8 11:39:40 EDT 2014
On Sunday, 8 June 2014 15:59:14 UTC+1, Roy Smith wrote:
> Why? I assume a language which promoted the global namespace to be in
> the attribute search path (which, as far as I can tell, is what we're
> talking about here) would implement hasattr and raising AttributeError
> in a consistent way.
It's slightly different. Although I used len() as an example, the idea is to allow any function to be used in this way, including local symbols.
e.g. I could define:
def squared(x):
return x * x
i = 3
i.squared() => 9
j = AClassThatImplements__mul__()
j.squared() => whatever j * j returns
but also:
class AnotherClass:
def __mul__(self, other):
...
def squared(self):
return specialised_method_for_calculating_squares()
k = AnotherClass()
k.squared() => calls method, not function
In this case, there is a problem with letting hasattr('squared') return True for these first two instances. See Ian's post for a description of the problem.
More information about the Python-list
mailing list