]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-42562: Fix issue when dis failed to parse function that has no line numbers ...
authorYurii Karabas <1998uriyyo@gmail.com>
Fri, 4 Dec 2020 15:20:53 +0000 (17:20 +0200)
committerGitHub <noreply@github.com>
Fri, 4 Dec 2020 15:20:53 +0000 (15:20 +0000)
Fix issue when dis failed to parse function that has only annotations

Lib/dis.py
Lib/test/test_dis.py
Misc/NEWS.d/next/Library/2020-12-03-22-42-03.bpo-42562.2hPmhi.rst [new file with mode: 0644]

index ea50f564c87dc72cd3cb1fc7dde08a76d92f2c45..ccbd65be73255a29f29ecf2f5518aa29560b3cb9 100644 (file)
@@ -384,7 +384,7 @@ def _disassemble_bytes(code, lasti=-1, varnames=None, names=None,
                        constants=None, cells=None, linestarts=None,
                        *, file=None, line_offset=0):
     # Omit the line number column entirely if we have no line number info
-    show_lineno = linestarts is not None
+    show_lineno = bool(linestarts)
     if show_lineno:
         maxlineno = max(linestarts.values()) + line_offset
         if maxlineno >= 1000:
index d0743d62e3d7940a5c4abb18968af30efaf8d50e..56d877151838f0970f220a80c28b9953088c6395 100644 (file)
@@ -166,6 +166,20 @@ dis_bug1333982 = """\
        bug1333982.__code__.co_firstlineno + 2,
        bug1333982.__code__.co_firstlineno + 1)
 
+
+def bug42562():
+    pass
+
+
+# Set line number for 'pass' to None
+bug42562.__code__ = bug42562.__code__.replace(co_linetable=b'\x04\x80\xff\x80')
+
+
+dis_bug42562 = """\
+          0 LOAD_CONST               0 (None)
+          2 RETURN_VALUE
+"""
+
 _BIG_LINENO_FORMAT = """\
 %3d           0 LOAD_GLOBAL              0 (spam)
               2 POP_TOP
@@ -520,6 +534,9 @@ class DisTests(unittest.TestCase):
 
         self.do_disassembly_test(bug1333982, dis_bug1333982)
 
+    def test_bug_42562(self):
+        self.do_disassembly_test(bug42562, dis_bug42562)
+
     def test_big_linenos(self):
         def func(count):
             namespace = {}
diff --git a/Misc/NEWS.d/next/Library/2020-12-03-22-42-03.bpo-42562.2hPmhi.rst b/Misc/NEWS.d/next/Library/2020-12-03-22-42-03.bpo-42562.2hPmhi.rst
new file mode 100644 (file)
index 0000000..4999da5
--- /dev/null
@@ -0,0 +1,2 @@
+Fix issue when dis failed to parse function that has no line numbers. Patch
+provided by Yurii Karabas.