On Thu, Dec 17, 2020 at 03:52:51PM +0300, Paul Sokolovsky wrote:

> But I did by now, and you didn't need to wait for me to do it, because
> "(a.b)()" does *exactly* what *you* or anybody else would think it
> does, based on your knowledge of what grouping parens in the
> expressions do. So again, "(a.b)()" first extracts a value of the "b"
> *attribute* from the object held in variable "a", then calls that
> value with 0 arguments.
> 
> That's in striking difference to "a.b()", which calls the *method* "b"
> of object held in variable "a".

In CPython, both generate exactly the same byte-code, and both will call 
any sort of object. Or *attempt* to call, since there is no guarantee 
that the attribute returned by `a.b` (with or without parens) will be a 
callable object.

You are imagining differences in behaviour which literally do not exist.


```
>>> dis.dis('a.b()')
  1           0 LOAD_NAME                0 (a)
              2 LOAD_METHOD              1 (b)
              4 CALL_METHOD              0
              6 RETURN_VALUE
>>> from types import SimpleNamespace
>>> a = SimpleNamespace()
>>> a.b = int
>>> a.b("123")
123
```



-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/A5WWXS27SESCBESVQSUOCT3ZUC5GJ7EQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to