Hello,

How would you feel if explicit parens were used to convey additional
semantic meaning? That seems like a pretty dumb question, because,
well, parens *are* used to convey additional semantic meaning. E.g.:

1 + 2 + 3   vs   1 + (2 + 3)

The result is the same, but somehow I wanted to emphasize that 2 and 3
should be added together, and somehow else.

a + b + c   vs   a + (b + c)

Here, there's even no guarantee of the same result, if we have user
objects with weirdly overloaded __add__().

Thanks for hanging with me so far, we're getting to the crux of the
question:

Do you think there can be difference between the following two
expressions:

obj.meth()
(obj.meth)()

?

The question is definitely with a trick (why else there would be the
intro), and first answer which comes to mind might not be the right
one. As a hint, to try to get a grounded answer to that question, it
would be useful to look at the difference in disassembly of the above
code in CPython3.6 vs CPython3.7 (or later):

python3.6 -m dis meth_call.py
python3.7 -m dis meth_call.py

Then, to try to explain the difference at the suitable level of
abstraction. If that doesn't provide enough differentiation, it might
be helpful to add the 3rd line:

t = obj.meth; t()

And run all 3 lines thru CPython3.7, and see if the pattern is now
visible, and a distortion in the pattern too. 

What would be the explanation for all that? 


For reference, the disassembly of the 3 lines with CPython3.7 is
provided:

  1           0 LOAD_NAME                0 (obj)
              2 LOAD_METHOD              1 (meth)
              4 CALL_METHOD              0
              6 POP_TOP

  2           8 LOAD_NAME                0 (obj)
             10 LOAD_METHOD              1 (meth)
             12 CALL_METHOD              0
             14 POP_TOP

  3          16 LOAD_NAME                0 (obj)
             18 LOAD_ATTR                1 (meth)
             20 STORE_NAME               2 (t)
             22 LOAD_NAME                2 (t)
             24 CALL_FUNCTION            0
             26 POP_TOP
...

-- 
Best regards,
 Paul                          mailto:pmis...@gmail.com
_______________________________________________
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/VGOUM3QYUIT4F2WDUJ224IDZ2MSQJD3E/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to