diff --git a/Lib/dis.py b/Lib/dis.py index c05b8e0dd86..c8313ac15a0 100644 --- a/Lib/dis.py +++ b/Lib/dis.py @@ -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 diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index 0e7c59c5797..805cd4e4c30 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -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 @@ -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: @@ -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: @@ -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 @@ -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) @@ -659,7 +659,7 @@ def _tryfinallyconst(b): POP_TOP RETURN_VALUE -None L3: PUSH_EXC_INFO + -- L3: PUSH_EXC_INFO %4d LOAD_FAST 1 (b) PUSH_NULL @@ -667,7 +667,7 @@ def _tryfinallyconst(b): POP_TOP RERAISE 0 -None L4: COPY 3 + -- L4: COPY 3 POP_EXCEPT RERAISE 1 ExceptionTable: @@ -693,7 +693,7 @@ 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 @@ -701,7 +701,7 @@ def _tryfinallyconst(b): POP_TOP RERAISE 0 -None L2: COPY 3 + -- L2: COPY 3 POP_EXCEPT RERAISE 1 ExceptionTable: @@ -730,7 +730,7 @@ def foo(x): return foo dis_nested_0 = """\ -None MAKE_CELL 0 (y) + -- MAKE_CELL 0 (y) %4d RESUME 0 @@ -752,7 +752,7 @@ def foo(x): dis_nested_1 = """%s Disassembly of : -None COPY_FREE_VARS 1 + -- COPY_FREE_VARS 1 MAKE_CELL 0 (x) %4d RESUME 0 @@ -779,7 +779,7 @@ def foo(x): dis_nested_2 = """%s Disassembly of at 0x..., file "%s", line %d>: -None COPY_FREE_VARS 1 + -- COPY_FREE_VARS 1 %4d RETURN_GENERATOR POP_TOP @@ -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 diff --git a/Misc/NEWS.d/next/Library/2023-11-23-12-37-22.gh-issue-112137.kM46Q6.rst b/Misc/NEWS.d/next/Library/2023-11-23-12-37-22.gh-issue-112137.kM46Q6.rst new file mode 100644 index 00000000000..1b2e41ae96f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-11-23-12-37-22.gh-issue-112137.kM46Q6.rst @@ -0,0 +1 @@ +Change :mod:`dis` output to display no-lineno as "--" instead of "None".