Terry J. Reedy <tjre...@udel.edu> added the comment:

The doc section in question is
https://docs.python.org/3/library/ast.html#ast.parse

I confirmed that 'break', 'continue', 'yield', and 'return' still parse, with 
the results how having "type_ignores=[]" added.
  'Module(body=[Expr(value=Yield())], type_ignores=[])'
I do not understand Nick's comment about 'await' as 'await' is not a legal 
statement'

The current initial paragraph says:
  "Parse the source into an AST node. Equivalent to compile(source, filename, 
mode, ast.PyCF_ONLY_AST)."

I suggest following this with:
  "If the AST node is compiled to a code object, there are additional syntax 
checks that can raise errors.  "For example, 'return' parses to a node, but is 
not legal outside of a def statement."

Hrvoje's suggested adding something like
  "If source contains a null character ('\0'), ValueError is raised."

I don't think that this is needed as ast.parse is explicitly noted as 
equivalent to a compile call, and the compile doc says "This function raises 
SyntaxError if the compiled source is invalid, and ValueError if the source 
contains null bytes."  (Should not that be 'null characters' given that 
*source* is now unicode?) This statement need not be repeated here.

----------
versions: +Python 3.11 -Python 2.7, Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue30637>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to