[issue6507] Enhance dis.dis to autocompile codestrings
Changes by Éric Araujo mer...@netwok.org: -- resolution: accepted - fixed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6507] Enhance dis.dis to autocompile codestrings
Nick Coghlan ncogh...@gmail.com added the comment: Committed (with some minor modifications) in r82471. Inspired by Yanov Aknin's ssc() tool, I've opened a new RFE (issue 9147) for a similarly enhanced show_code() implementation. -- stage: patch review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6507] Enhance dis.dis to autocompile codestrings
Scott Dial sc...@scottdial.com added the comment: disassemble_str should be private with an underscore. disassemble_string should've been private as well, while we are editing this module. -- nosy: +scott.dial ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6507] Enhance dis.dis to autocompile codestrings
Daniel Urban urban.dani...@gmail.com added the comment: disassemble_string should've been private as well, while we are editing this module. Attached the updated patch. -- Added file: http://bugs.python.org/file17839/issue6507_3.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6507] Enhance dis.dis to autocompile codestrings
Changes by Mark Dickinson dicki...@gmail.com: -- nosy: +mark.dickinson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6507] Enhance dis.dis to autocompile codestrings
Terry J. Reedy tjre...@udel.edu added the comment: Just today, someone posted the result of dis.dis('somebytes') and did not notice the error because dis blithely disassembles bytes as bytecodes, even in 3.x. (The person actually dissed a 2.x string). from dis import dis dis(b'cat') 0 DUP_TOPX29793 It is a natural thing to do, so I hope this is put in 3.2. Since the undocumented 'disassemble_string' now disassembles bytes, I think it should be renamed '_disassemble_bytes' instead of '_disassemble_string'. This would accord with the general effort to remove 2.x fossils from 3.x. Aside from that, it looks ready, from a reading review, to apply and test: doc addition, added tests, new function and else case, and rename. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6507] Enhance dis.dis to autocompile codestrings
Changes by Éric Araujo mer...@netwok.org: -- resolution: - accepted stage: commit review - patch review ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6507] Enhance dis.dis to autocompile codestrings
Nick Coghlan ncogh...@gmail.com added the comment: Missed the window for 2.7, but should be right for 3.2. There's a minor error in the documentation (strings need to be mentioned in the list of acceptable types), but I can fix that on commit. -- assignee: benjamin.peterson - ncoghlan priority: low - normal versions: -Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6507] Enhance dis.dis to autocompile codestrings
Benjamin Peterson benja...@python.org added the comment: disassemble_str should be private with an underscore. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6507] Enhance dis.dis to autocompile codestrings
Daniel Urban urban.dani...@gmail.com added the comment: Done. Attached new patch as issue6507_2_priv.diff. -- Added file: http://bugs.python.org/file17265/issue6507_2_priv.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6507] Enhance dis.dis to autocompile codestrings
Daniel Urban urban.dani...@gmail.com added the comment: Any chance, that my patch will be accepted? Is there a problem with it? Thanks. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6507] Enhance dis.dis to autocompile codestrings
Changes by Raymond Hettinger rhettin...@users.sourceforge.net: -- assignee: - benjamin.peterson nosy: +benjamin.peterson stage: needs patch - commit review versions: +Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6507] Enhance dis.dis to autocompile codestrings
Daniel Urban urban.dani...@gmail.com added the comment: I've made a patch, which adds a disassemble_str function to the dis module. The dis.dis function calls this function if x is a string. Added the following sentence to the documentation: Strings are first compiled to code objects with the :func:`compile` built-in function. Added two simle unittests. -- keywords: +patch nosy: +durban Added file: http://bugs.python.org/file16871/issue6507.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6507] Enhance dis.dis to autocompile codestrings
Raymond Hettinger rhettin...@users.sourceforge.net added the comment: +1 -- nosy: +rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6507] Enhance dis.dis to autocompile codestrings
Terry J. Reedy tjre...@udel.edu added the comment: Trying both 'eval' and 'exec' looks fine to me. Marking 'easy' because I expect it should be ;-) -- keywords: +easy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6507] Enhance dis.dis to autocompile codestrings
Georg Brandl ge...@python.org added the comment: As I explained on python-ideas, 'single' should not be tried. -- nosy: +georg.brandl ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6507] Enhance dis.dis to autocompile codestrings
Nick Coghlan ncogh...@gmail.com added the comment: As per Georg's suggestion, a better approach would look like: from dis import dis def dis_str(source): try: c = compile(source, '', 'eval') except SyntaxError: c = compile(source, '', 'exec') return dis(c) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6507] Enhance dis.dis to autocompile codestrings
New submission from Terry J. Reedy tjre...@udel.edu: dis.dis(ob) currently accepts a module, a class, a method, a function, or a code object. But for most uses I have seen on python-list, people start with a code snippet. They must then wrap that in a function or remember (or lookup) a call such as compile(code, '', 'exec') to make a code object. I propose that dis do the latter automatically. Dis already has to branch on the input class, so I assume adding another branch should not be difficult. On the Python ideas list, Steven D'Aprano raised the issue of 'exec' versus 'single' versus 'eval'. As far as dis is concerned, there seems to be no difference between 'exec' and 'single'. dis(compile('x = x+1', '', 'single')) 1 0 LOAD_NAME0 (x) 3 LOAD_CONST 0 (1) 6 BINARY_ADD 7 STORE_NAME 0 (x) 10 LOAD_CONST 1 (None) 13 RETURN_VALUE dis(compile('x = x+1', '', 'exec')) 1 0 LOAD_NAME0 (x) 3 LOAD_CONST 0 (1) 6 BINARY_ADD 7 STORE_NAME 0 (x) 10 LOAD_CONST 1 (None) 13 RETURN_VALUE Using 'exec' instead of 'eval' adds two spurious, but easily ignored, lines. dis(compile('x+1','', 'eval')) 1 0 LOAD_NAME0 (x) 3 LOAD_CONST 0 (1) 6 BINARY_ADD 7 RETURN_VALUE dis(compile('x+1', '', 'exec')) 1 0 LOAD_NAME0 (x) 3 LOAD_CONST 0 (1) 6 BINARY_ADD 7 POP_TOP 8 LOAD_CONST 1 (None) 11 RETURN_VALUE Between the current doc sentences For a single code sequence, it prints one line per bytecode instruction. and If no object is provided, it disassembles the last traceback. I propose adding the following two sentences. Strings are first compiled as statements to code objects with compile(string,'','exec'). For expressions, this adds a spurious POP_TOP and LOAD_CONST at the end. 'compile' should be cross-referenced to its listing under built-in functions. -- components: Library (Lib) messages: 90637 nosy: tjreedy severity: normal status: open title: Enhance dis.dis to autocompile codestrings type: feature request versions: Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6507] Enhance dis.dis to autocompile codestrings
Changes by Benjamin Peterson benja...@python.org: -- priority: - low stage: - needs patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6507] Enhance dis.dis to autocompile codestrings
Nick Coghlan ncogh...@gmail.com added the comment: Copying my suggestion (minus examples) over from the python-ideas thread: We could define it as trying the three modes in order (first 'eval', then 'single', then 'exec') moving on to the next option if it raises syntax error: from dis import dis def dis_str(source): modes = ('eval', 'single', 'exec') for mode in modes: try: c = compile(source, '', mode) break except SyntaxError: if mode is modes[-1]: raise return dis(c) -- nosy: +ncoghlan ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6507 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com