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.

Unsupported provider

classification
Title: dis.show_code() variant that accepts source strings (and returns rather than prints)
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: ncoghlan Nosy List: daniel.urban, flox, mark.dickinson, ncoghlan
Priority: normal Keywords: buildbot

Created on 2010-07-03 07:42 by ncoghlan, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (9)
msg109161 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2010-07-03 07:42
Add a new API in the dis module that:

1. Works like show_code() but returns a string rather than printing to stdout
2. Accepts source strings directly, similar to the dis.dis() changes for 3.2

Tentative name: get_code_info()

Inspired by Yanov Aknin's ssc() utility and the issue 6507 updates to dis.dis()
msg109166 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-07-03 09:04
Yes, please!
msg109185 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2010-07-03 15:11
Small correction to my first message: that would be Yaniv Aknin (not Yanov)
msg114104 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2010-08-17 08:04
Implemented in r84133
msg114105 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2010-08-17 08:05
Final name was dis.code_info() and it accepts functions, methods, code objects and source strings.
msg114107 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-08-17 09:11
The buildbot XP-4 3.x fails on test_dis.
http://www.python.org/dev/buildbot/all/builders/x86%20XP-4%203.x/builds/2770

test_code_info (test.test_dis.CodeInfoTests) ... FAIL
test_show_code (test.test_dis.CodeInfoTests) ... FAIL

======================================================================
FAIL: test_code_info (test.test_dis.CodeInfoTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\test\test_dis.py", line 359, in test_code_info
    self.assertEqual(dis.code_info(x), expected)
AssertionError: 'Name:              tricky\nFilename:          D:\\cygwin\\home\\db3l\\buildarea [truncated]... != 'Name:              tricky\nFilename:          D:\\cygwin\\home\\db3l\\buildarea [truncated]...
  Name:              tricky
  Filename:          D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\test\test_dis.py
  Argument count:    3
  Kw-only arguments: 3
  Number of locals:  8
  Stack size:        7
  Flags:             OPTIMIZED, NEWLOCALS, VARARGS, VARKEYWORDS, GENERATOR
  Constants:
     0: None
-    1: <code object f at 0x03D750F8, file "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\test\test_dis.py", line 246>
?                           - ^   ^
+    1: <code object f at 0x3d750f8, file "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\test\test_dis.py", line 246>
?                            ^   ^
  Variable names:
     0: x
     1: y
     2: z
     3: c
     4: d
     5: e
     6: args
     7: kwds
  Cell variables:
     0: e
     1: d
     2: f
     3: y
     4: x
     5: z

======================================================================
FAIL: test_show_code (test.test_dis.CodeInfoTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\test\test_dis.py", line 366, in test_show_code
    self.assertEqual(output.getvalue(), expected+"\n")
AssertionError: 'Name:              tricky\nFilename:          D:\\cygwin\\home\\db3l\\buildarea [truncated]... != 'Name:              tricky\nFilename:          D:\\cygwin\\home\\db3l\\buildarea [truncated]...
  Name:              tricky
  Filename:          D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\test\test_dis.py
  Argument count:    3
  Kw-only arguments: 3
  Number of locals:  8
  Stack size:        7
  Flags:             OPTIMIZED, NEWLOCALS, VARARGS, VARKEYWORDS, GENERATOR
  Constants:
     0: None
-    1: <code object f at 0x03D750F8, file "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\test\test_dis.py", line 246>
?                           - ^   ^
+    1: <code object f at 0x3d750f8, file "D:\cygwin\home\db3l\buildarea\3.x.bolen-windows\build\lib\test\test_dis.py", line 246>
?                            ^   ^
  Variable names:
     0: x
     1: y
     2: z
     3: c
     4: d
     5: e
     6: args
     7: kwds
  Cell variables:
     0: e
     1: d
     2: f
     3: y
     4: x
     5: z
msg114109 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2010-08-17 09:28
I changed the test to a regex match that ignores the specific ID value of the nested function in r84137. That should make the buildbots happier.
msg114114 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2010-08-17 11:30
Switching to a regex match made the backslashes in windows paths a problem. r84139 changes the test to just ignore all the variable info in the code_info results so we'll see how that goes.
msg114118 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2010-08-17 13:17
The windows buildbot still doesn't appear to be particularly happy, but this issue also doesn't appear to be the culprit anymore.
History
Date User Action Args
2022-04-11 14:57:03adminsetgithub: 53393
2010-08-17 13:17:02ncoghlansetstatus: open -> closed

messages: + msg114118
2010-08-17 11:30:33ncoghlansetmessages: + msg114114
2010-08-17 09:28:36ncoghlansetmessages: + msg114109
2010-08-17 09:11:17floxsetstatus: closed -> open

nosy: + flox
messages: + msg114107

keywords: + buildbot
2010-08-17 08:05:04ncoghlansetmessages: + msg114105
2010-08-17 08:04:14ncoghlansetstatus: open -> closed
resolution: accepted
messages: + msg114104

stage: resolved
2010-07-03 16:25:54daniel.urbansetnosy: + daniel.urban
2010-07-03 15:11:51ncoghlansetmessages: + msg109185
2010-07-03 09:04:04mark.dickinsonsetnosy: + mark.dickinson
messages: + msg109166
2010-07-03 07:42:40ncoghlancreate