https://github.com/python/cpython/commit/58d305cf387816c559602a95ba850856dc9b8129
commit: 58d305cf387816c559602a95ba850856dc9b8129
branch: main
author: Mikhail Efimov <[email protected]>
committer: Eclips4 <[email protected]>
date: 2025-07-21T15:25:25+03:00
summary:
gh-136438: Make sure `test_generated_cases` pass with all optimization levels
(#136594)
Fix the `test_generated_cases` to work with `-O` or `-OO` flags.
Previously, `test_generated_cases` was catching an `AssertionError` while
`Tools/cases_generator/optimizer_generator.py` used an `assert` statement.
This approach semantically incorrect, no one should trying to catch an
`AssertionError`!
Now the `assert` statement has been replaced with an explicit `raise
ValueError(...)` and the corresponding `self.assertRaisesRegex(AssertionError,
...)` has been updated to catch a `ValueError` instead.
files:
M Lib/test/test_generated_cases.py
M Tools/cases_generator/optimizer_generator.py
diff --git a/Lib/test/test_generated_cases.py b/Lib/test/test_generated_cases.py
index 81d4e39f5be1ee..ec44a0f9ce3fb3 100644
--- a/Lib/test/test_generated_cases.py
+++ b/Lib/test/test_generated_cases.py
@@ -2037,7 +2037,7 @@ def test_missing_override_failure(self):
"""
output = """
"""
- with self.assertRaisesRegex(AssertionError, "All abstract uops"):
+ with self.assertRaisesRegex(ValueError, "All abstract uops"):
self.run_cases_test(input, input2, output)
def test_validate_uop_input_length_mismatch(self):
diff --git a/Tools/cases_generator/optimizer_generator.py
b/Tools/cases_generator/optimizer_generator.py
index 81ae534bddae5c..ea9dd836d98e22 100644
--- a/Tools/cases_generator/optimizer_generator.py
+++ b/Tools/cases_generator/optimizer_generator.py
@@ -398,9 +398,9 @@ def generate_abstract_interpreter(
out.emit("\n")
base_uop_names = set([uop.name for uop in base.uops.values()])
for abstract_uop_name in abstract.uops:
- assert (
- abstract_uop_name in base_uop_names
- ), f"All abstract uops should override base uops, but
{abstract_uop_name} is not."
+ if abstract_uop_name not in base_uop_names:
+ raise ValueError(f"All abstract uops should override base uops, "
+ "but {abstract_uop_name} is not.")
for uop in base.uops.values():
override: Uop | None = None
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]