-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Support new ast features and node types introduced in Python 3.8 #2859
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
Conversation
Had to adjust the return type of ast.parse() from Module to AST, which is more truthful anyways.
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.
Thank you for the patch, but especially for incorporating these changes in the ast
module, this will be very useful.
I'm not very versed in interpreting the ADSL or converting it to code, so please take my review with a big grain of salt.
stdlib/3/_ast.pyi
Outdated
col_offset: int # TODO: Not all nodes have this | ||
if sys.version_info >= (3, 8): | ||
end_lineno: int | ||
end_col_offset: int # TODO: Not all nodes have this |
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.
Shouldn't these two attributes be Optional
?
stdlib/3/_ast.pyi
Outdated
|
||
class FunctionType(mod): | ||
argtypes = ... # type: typing.List[expr] | ||
returns = ... # type: expr |
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.
I'd prefer variable annotation syntax for new code (even if existing code in the file still uses comment syntax). Applies to classes below as well.
stdlib/3/_ast.pyi
Outdated
@@ -253,6 +270,14 @@ class Bytes(expr): | |||
class NameConstant(expr): | |||
value = ... # type: Any | |||
|
|||
if sys.version_info >= (3, 8): | |||
class Constant(expr): | |||
value = ... # type: expr |
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.
I guess this a an expr
, because constants can be assigned an arbitrary expression? I mainly ask, because the old constant classes all had more concrete attribute types like 'str', 'float' (or Any
in the case of NameConstant
).
Thanks for the very thorough code review. Note that I added |
To test with Python 3.8, this requires python/cpython#12295. The typeshed changes were in python/typeshed#2859 (and synced in #6540).
python/typeshed#2859 changed the return type. Module is a subclass of AST, so it's still correct, just less precise. Based on the PR description, this change was intentional. PiperOrigin-RevId: 239423111
Specifically:
TypeIgnore
,FunctionType
,Constant
andNamedExpr
AST
attributesend_lineno
,end_col_offset
, andtype_comment
Module.type_ignores
Str.kind
(that's new in 3.7 actually)ast.parse()
:type_comments=<bool>
andfeature_version=<int>
I had to adjust the return type of
ast.parse()
from Module toAST
, which is more truthful anyways.