Hello, On Tue, 15 Dec 2020 08:25:25 +0000 Jeff Allen <ja...@farowl.co.uk> wrote:
> On 13/12/2020 22:09, Paul Sokolovsky wrote: > > 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)() > > > > ? > > No. The value of an expression in parentheses is the value of the > expression inside the parentheses, and in this case does not affect > the order of evaluation. You're on the right track. (Well, I mean you're on the same track as me.) So, what's the order of evaluation and what's being evaluated at all? > > 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? > > The explanation is an optimisation introduced in 3.7 that the use of > an intermediate variable prevents. Right. But I would suggest us rising up in abstraction level a bit, and think not in terms of "intermediate variables" but in terms of "intermediate storage locations". More details in my today's reply to Chris Angelico. > The compiler applies it when it > can see the only use of the attribute is an immediately following > call. You're now just a step away from the "right answer". Will you make it? I did. And sorry, the whole point of the discussion if to see if the whole path, each step on it, and the final answer is as unavoidable as I now imagine them to be, so I can't push you towards it ;-). > Having burrowed into the implementation, Great! As I mentioned in the other replies, I brought implementation matters (disassembly) to represent the matter better. But the proper way is to start with semantics, and then consider how to implement it (and those considerations can have feedback effect on desired semantics too of course). So, regardless of whether it was done like that or not in that case (when LOAD_METHOD was introduced), let's think what semantics [could have] lead to LOAD_METHOD vs LOAD_ATTR implementation? [] > > Jeff Allen > -- 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/GHPXATZX5NHYH6EATP45BO7CFLLOSMBT/ Code of Conduct: http://python.org/psf/codeofconduct/