8000 bpo-39562: Prevent collision of future and compiler flags by isidentical · Pull Request #19230 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-39562: Prevent collision of future and compiler flags #19230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 22, 2020
Prev Previous commit
Next Next commit
Add a noticement header, use dicts for tests
  • Loading branch information
isidentical committed Apr 21, 2020
commit 5f8018bcc8b5a37cffaa5b9bd0d9d8e3bf4cead4
4 changes: 3 additions & 1 deletion Include/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ typedef struct {
#define CO_ASYNC_GENERATOR 0x0200

/* bpo-39562: These constant values are changed in Python 3.9
to prevent collision with compiler flags. */
to prevent collision with compiler flags. CO_FUTURE_ and PyCF_
constants must be kept unique. PyCF_ constants can use bits from
0x0100 to 0x10000. CO_FUTURE_ constants use bits starting at 0x20000. */
#define CO_FUTURE_DIVISION 0x20000
8000
#define CO_FUTURE_ABSOLUTE_IMPORT 0x40000 /* do absolute imports by default */
#define CO_FUTURE_WITH_STATEMENT 0x80000
Expand Down
5 changes: 5 additions & 0 deletions Include/compile.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ PyAPI_FUNC(PyCodeObject *) PyNode_Compile(struct _node *, const char *);
CO_FUTURE_UNICODE_LITERALS | CO_FUTURE_BARRY_AS_BDFL | \
CO_FUTURE_GENERATOR_STOP | CO_FUTURE_ANNOTATIONS)
#define PyCF_MASK_OBSOLETE (CO_NESTED)

/* bpo-39562: These constant values are changed in Python 3.9
to prevent collision with compiler flags. CO_FUTURE_ and PyCF_
constants must be kept unique. PyCF_ constants can use bits from
0x0100 to 0x10000. CO_FUTURE_ constants use bits starting at 0x20000. */
#define PyCF_SOURCE_IS_UTF8 0x0100
#define PyCF_DONT_IMPLY_DEDENT 0x0200
#define PyCF_ONLY_AST 0x0400
Expand Down
17 changes: 9 additions & 8 deletions Lib/test/test_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,17 @@ def test_badfuture10(self):
def test_ensure_flags_dont_clash(self):
# bpo-39562: test that future flags and compiler flags doesn't clash

# obtain future flags (CO_***) from the __future__ module
flags = [
getattr(__future__, future).compiler_flag
# 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.extend(
getattr(ast, flag) for flag in dir(ast) if flag.startswith("PyCF_")
)
self.assertCountEqual(set(flags), flags)
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
Expand Down
0