[issue39800] Inconsistent/incomplete disassembly of methods vs method source code

2020-02-29 Thread S Murthy
S Murthy added the comment: Yes, I know that a method body may contain more than just the return statement - I was referrring to the byte code for the method def f(x): return x**2. I don't think the output of dis.dis is correct here for the source string of f - it doesn't make sense for exam

[issue39800] Inconsistent/incomplete disassembly of methods vs method source code

2020-02-29 Thread Steven D'Aprano
Steven D'Aprano added the comment: Ah, I see now. I was using an older version of Python and the output of dis was different. It didn't recurse in to show the disassembly of the code object as well. > The first block of instructions here are for the def statement, and > the second block for

[issue39800] Inconsistent/incomplete disassembly of methods vs method source code

2020-02-29 Thread Steven D'Aprano
Steven D'Aprano added the comment: > BTW how else are methods/functions are created in Python except via def? Functions are objects like everything else in Python, so they have a type, which has a constructor: from types import FunctionType The documentation for FunctionType is a bit th

[issue39800] Inconsistent/incomplete disassembly of methods vs method source code

2020-02-29 Thread S Murthy
S Murthy added the comment: BTW how else are methods/functions are created in Python except via def? -- ___ Python tracker ___ ___

[issue39800] Inconsistent/incomplete disassembly of methods vs method source code

2020-02-29 Thread S Murthy
S Murthy added the comment: @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. >>> d

[issue39800] Inconsistent/incomplete disassembly of methods vs method source code

2020-02-29 Thread Steven D'Aprano
Steven D'Aprano added the comment: > would it not be better to for dis.dis to behave consistently for methods and > source strings of methods I don't think so. The inputs are different. One is a string containing a `def` statement, which is an executable statement. The other is a function or

[issue39800] Inconsistent/incomplete disassembly of methods vs method source code

2020-02-29 Thread S Murthy
New submission from S Murthy : I am using the dis module to look at source (and logical) lines of code vs corresponding bytecode instructions. I am bit confused by the output of dis.dis when disassembling a given method vs the corresponding source string, e.g. >>> def f(x): return x**2 >>> di