-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-35766: Change format for feature_version to (major, minor) #13992
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ | |
|
|
||
|
|
||
| def parse(source, filename='<unknown>', mode='exec', *, | ||
| type_comments=False, feature_version=-1): | ||
| type_comments=False, feature_version=None): | ||
| """ | ||
| Parse the source into an AST node. | ||
| Equivalent to compile(source, filename, mode, PyCF_ONLY_AST). | ||
|
|
@@ -37,6 +37,13 @@ def parse(source, filename='<unknown>', mode='exec', *, | |
| flags = PyCF_ONLY_AST | ||
| if type_comments: | ||
| flags |= PyCF_TYPE_COMMENTS | ||
| if isinstance(feature_version, tuple): | ||
| major, minor = feature_version # Should be a 2-tuple. | ||
| assert major == 3 | ||
| feature_version = minor | ||
| elif feature_version is None: | ||
| feature_version = -1 | ||
| # Else it should be an int giving the minor version for 3.x. | ||
| return compile(source, filename, mode, flags, | ||
| feature_version=feature_version) | ||
|
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. Oh. I didn't notice that that compile() has a feature_version parameter as well. If if's only used by AST and should not be used explicitly, would it make sense to rename it to _feature_version in compile()? By the way, maybe it would be better to declare the feature_version/_feature_version parameter as a keyword-only to avoid mistakes. In short, I suggest this change (+ run "make clinic"): |
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Change the format of feature_version to be a (major, minor) tuple. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that there's a subtle difference between "must equal to 3" (the call fails if it isn't) and "supported" -- versions outside the supported range are treated as the lowest or highest supported version, respectively.