Skip to content

Change dis output to display labels instead of offsets #112137

Closed
@iritkatriel

Description

@iritkatriel

TODO:

  • test for output with offsets
  • -- instead of None for missing line number? - in another PR.

Feature or enhancement

>>> def f(): ... for i in x: ... if y: ... z ... >>> dis.dis(f) 1 RESUME 0 2 LOAD_GLOBAL 0 (x) GET_ITER L1: FOR_ITER 22 (to L3) STORE_FAST 0 (i) 3 LOAD_GLOBAL 2 (y) TO_BOOL POP_JUMP_IF_TRUE 2 (to L2) JUMP_BACKWARD 16 (to L1) 4 L2: LOAD_GLOBAL 4 (z) POP_TOP JUMP_BACKWARD 24 (to L1) 2 L3: END_FOR RETURN_CONST 0 (None) 

This is easier to read than the current output of:

>>> dis.dis(f) 1 0 RESUME 0 2 2 LOAD_GLOBAL 0 (x) 12 GET_ITER >> 14 FOR_ITER 22 (to 62) 18 STORE_FAST 0 (i) 3 20 LOAD_GLOBAL 2 (y) 30 TO_BOOL 38 POP_JUMP_IF_TRUE 2 (to 46) 42 JUMP_BACKWARD 16 (to 14) 4 >> 46 LOAD_GLOBAL 4 (z) 56 POP_TOP 58 JUMP_BACKWARD 24 (to 14) 2 >> 62 END_FOR 64 RETURN_CONST 0 (None) 

Linked PRs

Metadata

Metadata

Assignees

Labels

stdlibPython modules in the Lib dirtype-featureA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions