This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author smurthy
Recipients smurthy, steven.daprano
Date 2020-02-29.17:09:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1582996194.04.0.173487936973.issue39800@roundup.psfhosted.org>
In-reply-to
Content
@steven.daprano In this case, the method f was created by via def. And calling dis.dis(s) where s is the source code of f (say s = inspect.getsource(f)) shows the bytecode both for the header and the body, as is clear enough from the example I first posted.

>>> dis.dis('def f(x): return x**2')
  1 0 LOAD_CONST               0 (<code object f at 0x10b0f7f60, file "<dis>", line 1>)
  2 LOAD_CONST               1 ('f')
  4 MAKE_FUNCTION            0
  6 STORE_NAME               0 (f)
  8 LOAD_CONST               2 (None)
 10 RETURN_VALUE

Disassembly of <code object f at 0x10b0f7f60, file "<dis>", line 1>:
  1 0 LOAD_FAST              0 (x)
  2 LOAD_CONST               1 (2)
  4 BINARY_POWER
  6 RETURN_VALUE

The first block of instructions here are for the def statement, and the second block for the return statement.
History
Date User Action Args
2020-02-29 17:09:54smurthysetrecipients: + smurthy, steven.daprano
2020-02-29 17:09:54smurthysetmessageid: <1582996194.04.0.173487936973.issue39800@roundup.psfhosted.org>
2020-02-29 17:09:54smurthylinkissue39800 messages
2020-02-29 17:09:53smurthycreate