Conversation
Had to adjust the return type of ast.parse() from Module to AST, which is more truthful anyways.
srittau
left a comment
There was a problem hiding this comment.
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.
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.
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
|
|
||
| if sys.version_info >= (3, 8): | ||
| class Constant(expr): | ||
| value = ... # type: expr |
There was a problem hiding this comment.
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,ConstantandNamedExprASTattributesend_lineno,end_col_offset, andtype_commentModule.type_ignoresStr.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.