Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 89ddea4

Browse files
authored
gh-112137: change dis output to show no-lineno as -- instead of None (#112335)
1 parent 9e56eed commit 89ddea4

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

Lib/dis.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,8 @@ def _disassemble(self, lineno_width=3, mark_as_current=False, offset_width=0):
478478
if self.starts_line:
479479
lineno_fmt = "%%%dd" if self.line_number is not None else "%%%ds"
480480
lineno_fmt = lineno_fmt % lineno_width
481-
fields.append(lineno_fmt % self.line_number)
481+
lineno = self.line_number if self.line_number is not None else '--'
482+
fields.append(lineno_fmt % lineno)
482483
else:
483484
fields.append(' ' * lineno_width)
484485
# Column: Label

Lib/test/test_dis.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def wrap_func_w_kwargs():
412412
%4d L2: LOAD_FAST_CHECK 1 (tb)
413413
RETURN_VALUE
414414
415-
None L3: PUSH_EXC_INFO
415+
-- L3: PUSH_EXC_INFO
416416
417417
%4d LOAD_GLOBAL 0 (Exception)
418418
CHECK_EXC_MATCH
@@ -430,14 +430,14 @@ def wrap_func_w_kwargs():
430430
%4d LOAD_FAST 1 (tb)
431431
RETURN_VALUE
432432
433-
None L6: LOAD_CONST 0 (None)
433+
-- L6: LOAD_CONST 0 (None)
434434
STORE_FAST 0 (e)
435435
DELETE_FAST 0 (e)
436436
RERAISE 1
437437
438438
%4d L7: RERAISE 0
439439
440-
None L8: COPY 3
440+
-- L8: COPY 3
441441
POP_EXCEPT
442442
RERAISE 1
443443
ExceptionTable:
@@ -518,7 +518,7 @@ def _with(c):
518518
STORE_FAST 2 (y)
519519
RETURN_CONST 0 (None)
520520
521-
None L6: COPY 3
521+
-- L6: COPY 3
522522
POP_EXCEPT
523523
RERAISE 1
524524
ExceptionTable:
@@ -576,11 +576,11 @@ async def _asyncwith(c):
576576
577577
%4d L12: CLEANUP_THROW
578578
579-
None L13: JUMP_BACKWARD 26 (to L5)
579+
-- L13: JUMP_BACKWARD 26 (to L5)
580580
581581
%4d L14: CLEANUP_THROW
582582
583-
None L15: JUMP_BACKWARD 11 (to L11)
583+
-- L15: JUMP_BACKWARD 11 (to L11)
584584
585585
%4d L16: PUSH_EXC_INFO
586586
WITH_EXCEPT_START
@@ -604,7 +604,7 @@ async def _asyncwith(c):
604604
STORE_FAST 2 (y)
605605
RETURN_CONST 0 (None)
606606
607-
None L24: COPY 3
607+
-- L24: COPY 3
608608
POP_EXCEPT
609609
RERAISE 1
610610
L25: CALL_INTRINSIC_1 3 (INTRINSIC_STOPITERATION_ERROR)
@@ -659,15 +659,15 @@ def _tryfinallyconst(b):
659659
POP_TOP
660660
RETURN_VALUE
661661
662-
None L3: PUSH_EXC_INFO
662+
-- L3: PUSH_EXC_INFO
663663
664664
%4d LOAD_FAST 1 (b)
665665
PUSH_NULL
666666
CALL 0
667667
POP_TOP
668668
RERAISE 0
669669
670-
None L4: COPY 3
670+
-- L4: COPY 3
671671
POP_EXCEPT
672672
RERAISE 1
673673
ExceptionTable:
@@ -693,15 +693,15 @@ def _tryfinallyconst(b):
693693
POP_TOP
694694
RETURN_CONST 1 (1)
695695
696-
None L1: PUSH_EXC_INFO
696+
-- L1: PUSH_EXC_INFO
697697
698698
%4d LOAD_FAST 0 (b)
699699
PUSH_NULL
700700
CALL 0
701701
POP_TOP
702702
RERAISE 0
703703
704-
None L2: COPY 3
704+
-- L2: COPY 3
705705
POP_EXCEPT
706706
RERAISE 1
707707
ExceptionTable:
@@ -730,7 +730,7 @@ def foo(x):
730730
return foo
731731

732732
dis_nested_0 = """\
733-
None MAKE_CELL 0 (y)
733+
-- MAKE_CELL 0 (y)
734734
735735
%4d RESUME 0
736736
@@ -752,7 +752,7 @@ def foo(x):
752752

753753
dis_nested_1 = """%s
754754
Disassembly of <code object foo at 0x..., file "%s", line %d>:
755-
None COPY_FREE_VARS 1
755+
-- COPY_FREE_VARS 1
756756
MAKE_CELL 0 (x)
757757
758758
%4d RESUME 0
@@ -779,7 +779,7 @@ def foo(x):
779779

780780
dis_nested_2 = """%s
781781
Disassembly of <code object <genexpr> at 0x..., file "%s", line %d>:
782-
None COPY_FREE_VARS 1
782+
-- COPY_FREE_VARS 1
783783
784784
%4d RETURN_GENERATOR
785785
POP_TOP
@@ -797,7 +797,7 @@ def foo(x):
797797
L3: END_FOR
798798
RETURN_CONST 0 (None)
799799
800-
None L4: CALL_INTRINSIC_1 3 (INTRINSIC_STOPITERATION_ERROR)
800+
-- L4: CALL_INTRINSIC_1 3 (INTRINSIC_STOPITERATION_ERROR)
801801
RERAISE 1
802802
ExceptionTable:
803803
L1 to L4 -> L4 [0] lasti
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Change :mod:`dis` output to display no-lineno as "--" instead of "None".

0 commit comments

Comments
 (0)