[Python-checkins] bpo-42562: Fix issue when dis failed to parse function that has no line numbers (GH-23632)

markshannon webhook-mailer at python.org
Fri Dec 4 10:21:03 EST 2020


https://github.com/python/cpython/commit/f24b8101a01fa98b1e3ec042ba896aeb4c24d4bc
commit: f24b8101a01fa98b1e3ec042ba896aeb4c24d4bc
branch: master
author: Yurii Karabas <1998uriyyo at gmail.com>
committer: markshannon <mark at hotpy.org>
date: 2020-12-04T15:20:53Z
summary:

bpo-42562: Fix issue when dis failed to parse function that has no line numbers (GH-23632)

Fix issue when dis failed to parse function that has only annotations

files:
A Misc/NEWS.d/next/Library/2020-12-03-22-42-03.bpo-42562.2hPmhi.rst
M Lib/dis.py
M Lib/test/test_dis.py

diff --git a/Lib/dis.py b/Lib/dis.py
index ea50f564c87dc..ccbd65be73255 100644
--- a/Lib/dis.py
+++ b/Lib/dis.py
@@ -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:
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index d0743d62e3d79..56d877151838f 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -166,6 +166,20 @@ def bug1333982(x=[]):
        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 @@ def test_bug_1333982(self):
 
         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
index 0000000000000..4999da509c291
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-12-03-22-42-03.bpo-42562.2hPmhi.rst
@@ -0,0 +1,2 @@
+Fix issue when dis failed to parse function that has no line numbers. Patch
+provided by Yurii Karabas.



More information about the Python-checkins mailing list