Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dis.show_code() variant that accepts source strings (and returns rather than prints) #53393

Closed
ncoghlan opened this issue Jul 3, 2010 · 9 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ncoghlan
Copy link
Contributor

ncoghlan commented Jul 3, 2010

BPO 9147
Nosy @mdickinson, @ncoghlan, @florentx, @durban

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/ncoghlan'
closed_at = <Date 2010-08-17.13:17:02.558>
created_at = <Date 2010-07-03.07:42:40.056>
labels = ['type-feature', 'library']
title = 'dis.show_code() variant that accepts source strings (and returns rather than prints)'
updated_at = <Date 2010-08-17.13:17:02.556>
user = 'https://github.com/ncoghlan'

bugs.python.org fields:

activity = <Date 2010-08-17.13:17:02.556>
actor = 'ncoghlan'
assignee = 'ncoghlan'
closed = True
closed_date = <Date 2010-08-17.13:17:02.558>
closer = 'ncoghlan'
components = ['Library (Lib)']
creation = <Date 2010-07-03.07:42:40.056>
creator = 'ncoghlan'
dependencies = []
files = []
hgrepos = []
issue_num = 9147
keywords = ['buildbot']
message_count = 9.0
messages = ['109161', '109166', '109185', '114104', '114105', '114107', '114109', '114114', '114118']
nosy_count = 4.0
nosy_names = ['mark.dickinson', 'ncoghlan', 'flox', 'daniel.urban']
pr_nums = []
priority = 'normal'
resolution = 'accepted'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue9147'
versions = ['Python 3.2']

@ncoghlan
Copy link
Contributor Author

ncoghlan commented Jul 3, 2010

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 bpo-6507 updates to dis.dis()

@ncoghlan ncoghlan self-assigned this Jul 3, 2010
@ncoghlan ncoghlan added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Jul 3, 2010
@mdickinson
Copy link
Member

Yes, please!

@ncoghlan
Copy link
Contributor Author

ncoghlan commented Jul 3, 2010

Small correction to my first message: that would be Yaniv Aknin (not Yanov)

@ncoghlan
Copy link
Contributor Author

Implemented in r84133

@ncoghlan
Copy link
Contributor Author

Final name was dis.code_info() and it accepts functions, methods, code objects and source strings.

@florentx
Copy link
Mannequin

florentx mannequin commented Aug 17, 2010

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

@florentx florentx mannequin reopened this Aug 17, 2010
@ncoghlan
Copy link
Contributor Author

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.

@ncoghlan
Copy link
Contributor Author

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.

@ncoghlan
Copy link
Contributor Author

The windows buildbot still doesn't appear to be particularly happy, but this issue also doesn't appear to be the culprit anymore.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants