Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
984c8158d6d207ebf0003c14888d7cd943ad1094d6560a1005f8018bb225c610b8936eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -18,12 +18,18 @@ 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: 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 | ||
| #define PyCF_IGNORE_COOKIE 0x0800 | ||
| #define PyCF_TYPE_COMMENTS 0x1000 | ||
| #define PyCF_ALLOW_TOP_LEVEL_AWAIT 0x2000 | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How many bits are free for incoming compiler flags? Two? 0x4000 and 0x8000? MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and | ||
| #define PyCF_COMPILE_MASK (PyCF_ONLY_AST | PyCF_ALLOW_TOP_LEVEL_AWAIT | \ | ||
| PyCF_TYPE_COMMENTS | PyCF_DONT_IMPLY_DEDENT) | ||
| #ifndef Py_LIMITED_API | ||
| typedef struct { | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -68,14 +68,14 @@ | ||
| # this module. | ||
| CO_NESTED = 0x0010 # nested_scopes | ||
| CO_GENERATOR_ALLOWED = 0 # generators (obsolete, was 0x1000) | ||
| CO_FUTURE_DIVISION = 0x2000 # division | ||
| CO_FUTURE_ABSOLUTE_IMPORT = 0x4000 # perform absolute imports by default | ||
| CO_FUTURE_WITH_STATEMENT = 0x8000 # with statement | ||
| CO_FUTURE_PRINT_FUNCTION = 0x10000 # print function | ||
| CO_FUTURE_UNICODE_LITERALS = 0x20000 # unicode string literals | ||
| CO_FUTURE_BARRY_AS_BDFL = 0x40000 | ||
| CO_FUTURE_GENERATOR_STOP = 0x80000 # StopIteration becomes RuntimeError in generators | ||
| CO_FUTURE_ANNOTATIONS = 0x100000 # annotations become strings at runtime | ||
| CO_FUTURE_DIVISION = 0x20000 # division | ||
isidentical marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| CO_FUTURE_ABSOLUTE_IMPORT = 0x40000 # perform absolute imports by default | ||
| CO_FUTURE_WITH_STATEMENT = 0x80000 # with statement | ||
| CO_FUTURE_PRINT_FUNCTION = 0x100000 # print function | ||
| CO_FUTURE_UNICODE_LITERALS = 0x200000 # unicode string literals | ||
| CO_FUTURE_BARRY_AS_BDFL = 0x400000 | ||
| CO_FUTURE_GENERATOR_STOP = 0x800000 # StopIteration becomes RuntimeError in generators | ||
| CO_FUTURE_ANNOTATIONS = 0x1000000 # annotations become strings at runtime | ||
| class _Feature: | ||
| def __init__(self, optionalRelease, mandatoryRelease, compiler_flag): | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| # Test various flavors of legal and illegal future statements | ||
| import __future__ | ||
isidentical marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| import ast | ||
| import unittest | ||
| from test import support | ||
| from textwrap import dedent | ||
| @@ -75,6 +77,21 @@ def test_badfuture10(self): | ||
| from test import badsyntax_future10 | ||
| self.check_syntax_error(cm.exception, "badsyntax_future10", 3) | ||
| def test_ensure_flags_dont_clash(self): | ||
isidentical marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| # 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 | ||
Uh oh!
There was an error while loading. Please reload this page.