From 3ec2035bec7ded6a9ae3ed4ce0aae6b9c866d2b0 Mon Sep 17 00:00:00 2001
From: Yurii Karabas <1998uriyyo@gmail.com>
Date: Thu, 3 Dec 2020 22:42:24 +0200
Subject: [PATCH 1/4] Fix issue when dis failed to parse function that has only
annotations
---
Lib/dis.py | 2 +-
Lib/test/test_dis.py | 13 +++++++++++++
.../2020-12-03-22-42-03.bpo-42562.2hPmhi.rst | 2 ++
3 files changed, 16 insertions(+), 1 deletion(-)
create mode 100644 Misc/NEWS.d/next/Library/2020-12-03-22-42-03.bpo-42562.2hPmhi.rst
diff --git a/Lib/dis.py b/Lib/dis.py
index ea50f564c87dc7..ccbd65be73255a 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 d0743d62e3d794..9bce894c54c870 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -166,6 +166,16 @@ def bug1333982(x=[]):
bug1333982.__code__.co_firstlineno + 2,
bug1333982.__code__.co_firstlineno + 1)
+
+def bug42562():
+ a: int
+
+
+dis_bug42562 = """\
+ 0 LOAD_CONST 0 (None)
+ 2 RETURN_VALUE
+"""
+
_BIG_LINENO_FORMAT = """\
%3d 0 LOAD_GLOBAL 0 (spam)
2 POP_TOP
@@ -520,6 +530,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 00000000000000..dc9343a9fe40b5
--- /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 only annotations. Patch
+provided by Yurii Karabas.
From de7f1743c0e6bf1124c19a98ef9698989767c3c3 Mon Sep 17 00:00:00 2001
From: Yurii Karabas <1998uriyyo@gmail.com>
Date: Fri, 4 Dec 2020 14:47:34 +0200
Subject: [PATCH 2/4] Update bug42562 test
---
Lib/test/test_dis.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index 9bce894c54c870..0d91e884679d05 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -168,7 +168,10 @@ def bug1333982(x=[]):
def bug42562():
- a: int
+ pass
+
+
+bug42562.__code__ = bug42562.__code__.replace(co_linetable=b'\x04\x80\xff\x80')
dis_bug42562 = """\
From 86d6babb6f2cc2c481ca9d7f70ffc2f5104bc0f0 Mon Sep 17 00:00:00 2001
From: Yurii Karabas <1998uriyyo@gmail.com>
Date: Fri, 4 Dec 2020 15:15:47 +0200
Subject: [PATCH 3/4] Add comment to make things clear
---
Lib/test/test_dis.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index 0d91e884679d05..56d877151838f0 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -171,6 +171,7 @@ def bug42562():
pass
+# Set line number for 'pass' to None
bug42562.__code__ = bug42562.__code__.replace(co_linetable=b'\x04\x80\xff\x80')
From ac8de1e2e2bb2abf3dbf6af0df0c8703e93cc779 Mon Sep 17 00:00:00 2001
From: Yurii Karabas <1998uriyyo@gmail.com>
Date: Fri, 4 Dec 2020 15:58:15 +0200
Subject: [PATCH 4/4] Update News
---
.../next/Library/2020-12-03-22-42-03.bpo-42562.2hPmhi.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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
index dc9343a9fe40b5..4999da509c2913 100644
--- 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
@@ -1,2 +1,2 @@
-Fix issue when dis failed to parse function that has only annotations. Patch
+Fix issue when dis failed to parse function that has no line numbers. Patch
provided by Yurii Karabas.