Steven D'Aprano <steve+pyt...@pearwood.info> 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 method object, which may or may not have been created by a `def` statement. (You can, although not easily, assemble a function object yourself without using either `def` or `lambda` directly.) The `def` statement assembles a function object out of a pre-compiled body, and that's what dis shows when you give it a source code string that happens to contain a `def`. It's just another statement, like an import or loop or assignment. The contents of the body (the code object) isn't shown because the byte-code generated for a `def` knows nothing about the contents of the body. If you want to know the contents of the body, you have to look at the body (the code object) itself. ---------- nosy: +steven.daprano _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39800> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com