bpo-39562: Prevent collision of future and compiler flags (GH-19230)

The constant values of future flags in the __future__ module
is updated in order to prevent collision with compiler flags.
Previously PyCF_ALLOW_TOP_LEVEL_AWAIT was clashing
with CO_FUTURE_DIVISION.
This commit is contained in:
Batuhan Taşkaya 2020-04-22 19:09:03 +03:00 committed by GitHub
parent 9b49893900
commit 4454057269
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 21 deletions

View file

@ -1,5 +1,7 @@
# Test various flavors of legal and illegal future statements
import __future__
import ast
import unittest
from test import support
from textwrap import dedent
@ -75,6 +77,21 @@ class FutureTest(unittest.TestCase):
from test import badsyntax_future10
self.check_syntax_error(cm.exception, "badsyntax_future10", 3)
def test_ensure_flags_dont_clash(self):
# bpo-39562: test that future flags and compiler flags doesn't clash
# obtain future flags (CO_FUTURE_***) from the __future__ module
flags = {
f"CO_FUTURE_{future.upper()}": getattr(__future__, future).compiler_flag
for future in __future__.all_feature_names
}
# obtain some of the exported compiler flags (PyCF_***) from the ast module
flags |= {
flag: getattr(ast, flag)
for flag in dir(ast) if flag.startswith("PyCF_")
}
self.assertCountEqual(set(flags.values()), flags.values())
def test_parserhack(self):
# test that the parser.c::future_hack function works as expected
# Note: although this test must pass, it's not testing the original