Content-Length: 4136 | pFad | http://github.com/python/cpython/pull/136478.patch
thub.com
From e4f8fa6d75c8649aff278a5f1825106dde954097 Mon Sep 17 00:00:00 2001
From: donBarbos
Date: Wed, 9 Jul 2025 20:50:41 +0400
Subject: [PATCH 1/2] Make sure `test_compile` pass with all optimization
levels
---
Lib/test/test_compile.py | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 57e5f29b015637..172e03a8a8115f 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -583,18 +583,19 @@ def test_compile_ast(self):
with open(fname, encoding='utf-8') as f:
fcontents = f.read()
sample_code = [
- ['', 'x = 5'],
- ['', """if True:\n pass\n"""],
- ['', """for n in [1, 2, 3]:\n print(n)\n"""],
- ['', """def foo():\n pass\nfoo()\n"""],
- [fname, fcontents],
+ [2, '', 'x = 5'],
+ [2, '', """if True:\n pass\n"""],
+ [1, '', """for n in [1, 2, 3]:\n print(n)\n"""],
+ [1, '', """def foo():\n pass\nfoo()\n"""],
+ [0, fname, fcontents],
]
- for fname, code in sample_code:
- co1 = compile(code, '%s1' % fname, 'exec')
- ast = compile(code, '%s2' % fname, 'exec', _ast.PyCF_ONLY_AST)
+ for optval, fname, code in sample_code:
+ co1 = compile(code, '%s1' % fname, 'exec', optimize=optval)
+ ast = compile(code, '%s2' % fname, 'exec', _ast.PyCF_ONLY_AST,
+ optimize=optval)
self.assertTrue(type(ast) == _ast.Module)
- co2 = compile(ast, '%s3' % fname, 'exec')
+ co2 = compile(ast, '%s3' % fname, 'exec', optimize=optval)
self.assertEqual(co1, co2)
# the code object's filename comes from the second compilation step
self.assertEqual(co2.co_filename, '%s3' % fname)
@@ -823,8 +824,10 @@ def f():
else:
return "unused"
- self.assertEqual(f.__code__.co_consts,
- (f.__doc__, "used"))
+ if f.__doc__ is None:
+ self.assertEqual(f.__code__.co_consts, (True, "used"))
+ else:
+ self.assertEqual(f.__code__.co_consts, (f.__doc__, "used"))
@support.cpython_only
def test_remove_unused_consts_no_docstring(self):
@@ -862,14 +865,17 @@ def test_remove_unused_consts_extended_args(self):
# Stripping unused constants is not a strict requirement for the
# Python semantics, it's a more an implementation detail.
- @support.cpython_only
def test_strip_unused_None(self):
# Python 3.10rc1 appended None to co_consts when None is not used
# at all. See bpo-45056.
def f1():
"docstring"
return 42
- self.assertEqual(f1.__code__.co_consts, (f1.__doc__,))
+
+ if f1.__doc__ is None:
+ self.assertEqual(f1.__code__.co_consts, (42,))
+ else:
+ self.assertEqual(f1.__code__.co_consts, (f1.__doc__,))
# This is a regression test for a CPython specific peephole optimizer
# implementation bug present in a few releases. It's assertion verifies
From 4911e72d9cb8352e77e68ed3f653a73d2ee69eaa Mon Sep 17 00:00:00 2001
From: donBarbos
Date: Thu, 10 Jul 2025 13:23:09 +0400
Subject: [PATCH 2/2] Back @support.cpython_only
---
Lib/test/test_compile.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 172e03a8a8115f..8b6cfec44fdeb4 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -865,6 +865,7 @@ def test_remove_unused_consts_extended_args(self):
# Stripping unused constants is not a strict requirement for the
# Python semantics, it's a more an implementation detail.
+ @support.cpython_only
def test_strip_unused_None(self):
# Python 3.10rc1 appended None to co_consts when None is not used
# at all. See bpo-45056.
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/python/cpython/pull/136478.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy