gh-126072: do not add None to co_consts if there is no docstring (GH-126101)

This commit is contained in:
Xuanteng Huang 2024-10-30 17:01:09 +08:00 committed by GitHub
parent 2ab377a47c
commit 35df4eb959
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 148 additions and 58 deletions

View file

@ -834,7 +834,7 @@ class TestSpecifics(unittest.TestCase):
return "unused"
self.assertEqual(f.__code__.co_consts,
(None, "used"))
(True, "used"))
@support.cpython_only
def test_remove_unused_consts_extended_args(self):
@ -852,9 +852,9 @@ class TestSpecifics(unittest.TestCase):
eval(compile(code, "file.py", "exec"), g)
exec(code, g)
f = g['f']
expected = tuple([None, ''] + [f't{i}' for i in range(N)])
expected = tuple([''] + [f't{i}' for i in range(N)])
self.assertEqual(f.__code__.co_consts, expected)
expected = "".join(expected[2:])
expected = "".join(expected[1:])
self.assertEqual(expected, f())
# Stripping unused constants is not a strict requirement for the
@ -1244,7 +1244,7 @@ class TestSpecifics(unittest.TestCase):
y)
genexp_lines = [0, 4, 2, 0, 4]
genexp_code = return_genexp.__code__.co_consts[1]
genexp_code = return_genexp.__code__.co_consts[0]
code_lines = self.get_code_lines(genexp_code)
self.assertEqual(genexp_lines, code_lines)