8000 gh-112137: change dis output to show no-lineno as -- instead of None by iritkatriel · Pull Request #112335 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-112137: change dis output to show no-lineno as -- instead of None #112335

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

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,8 @@ def _disassemble(self, lineno_width=3, mark_as_current=False, offset_width=0):
if self.starts_line:
lineno_fmt = "%%%dd" if self.line_number is not None else "%%%ds"
lineno_fmt = lineno_fmt % lineno_width
fields.append(lineno_fmt % self.line_number)
lineno = self.line_number if self.line_number is not None else '--'
fields.append(lineno_fmt % lineno)
else:
fields.append(' ' * lineno_width)
# Column: Label
Expand Down
30 changes: 15 additions & 15 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def wrap_func_w_kwargs():
%4d L2: LOAD_FAST_CHECK 1 (tb)
RETURN_VALUE

None L3: PUSH_EXC_INFO
-- L3: PUSH_EXC_INFO

%4d LOAD_GLOBAL 0 (Exception)
CHECK_EXC_MATCH
Expand All @@ -430,14 +430,14 @@ def wrap_func_w_kwargs():
%4d LOAD_FAST 1 (tb)
RETURN_VALUE

None L6: LOAD_CONST 0 (None)
-- L6: LOAD_CONST 0 (None)
STORE_FAST 0 (e)
DELETE_FAST 0 (e)
RERAISE 1

%4d L7: RERAISE 0

None L8: COPY 3
-- L8: COPY 3
POP_EXCEPT
RERAISE 1
ExceptionTable:
Expand Down Expand Up @@ -518,7 +518,7 @@ def _with(c):
STORE_FAST 2 (y)
RETURN_CONST 0 (None)

None L6: COPY 3
-- L6: COPY 3
POP_EXCEPT
RERAISE 1
ExceptionTable:
Expand Down Expand Up @@ -576,11 +576,11 @@ async def _asyncwith(c):

%4d L12: CLEANUP_THROW

None L13: JUMP_BACKWARD 26 (to L5)
-- L13: JUMP_BACKWARD 26 (to L5)

%4d L14: CLEANUP_THROW

None L15: JUMP_BACKWARD 11 (to L11)
-- L15: JUMP_BACKWARD 11 (to L11)

%4d L16: PUSH_EXC_INFO
WITH_EXCEPT_START
Expand All @@ -604,7 +604,7 @@ async def _asyncwith(c):
STORE_FAST 2 (y)
RETURN_CONST 0 (None)

None L24: COPY 3
-- L24: COPY 3
POP_EXCEPT
RERAISE 1
L25: CALL_INTRINSIC_1 3 (INTRINSIC_STOPITERATION_ERROR)
Expand Down Expand Up @@ -659,15 +659,15 @@ def _tryfinallyconst(b):
POP_TOP
RETURN_VALUE

None L3: PUSH_EXC_INFO
-- L3: PUSH_EXC_INFO

%4d LOAD_FAST 1 (b)
PUSH_NULL
CALL 0
POP_TOP
RERAISE 0

None L4: COPY 3
-- L4: COPY 3
POP_EXCEPT
RERAISE 1
ExceptionTable:
Expand All @@ -693,15 +693,15 @@ def _tryfinallyconst(b):
POP_TOP
RETURN_CONST 1 (1)

None L1: PUSH_EXC_INFO
-- L1: PUSH_EXC_INFO

%4d LOAD_FAST 0 (b)
PUSH_NULL
CALL 0
POP_TOP
RERAISE 0

None L2: COPY 3
-- L2: COPY 3
POP_EXCEPT
RERAISE 1
ExceptionTable:
Expand Down Expand Up @@ -730,7 +730,7 @@ def foo(x):
return foo

dis_nested_0 = """\
None MAKE_CELL 0 (y)
-- MAKE_CELL 0 (y)

%4d RESUME 0

Expand All @@ -752,7 +752,7 @@ def foo(x):

dis_nested_1 = """%s
Disassembly of <code object foo at 0x..., file "%s", line %d>:
None COPY_FREE_VARS 1
-- COPY_FREE_VARS 1
MAKE_CELL 0 (x)

%4d RESUME 0
Expand All @@ -779,7 +779,7 @@ def foo(x):

dis_nested_2 = """%s
Disassembly of <code object <genexpr> at 0x..., file "%s", line %d>:
None COPY_FREE_VARS 1
-- COPY_FREE_VARS 1

%4d RETURN_GENERATOR
POP_TOP
Expand All @@ -797,7 +797,7 @@ def foo(x):
L3: END_FOR
RETURN_CONST 0 (None)

None L4: CALL_INTRINSIC_1 3 (INTRINSIC_STOPITERATION_ERROR)
-- L4: CALL_INTRINSIC_1 3 (INTRINSIC_STOPITERATION_ERROR)
RERAISE 1
ExceptionTable:
L1 to L4 -> L4 [0] lasti
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Change :mod:`dis` output to display no-lineno as "--" instead of "None".
0