Skip to main content

parse_py_expr_stmt

Function parse_py_expr_stmt 

Source
pub fn parse_py_expr_stmt(s: &str) -> Result<Option<PyExpr>, PyExprError>
Expand description

Parse a whole string the way _parse_annotation does — plain ast.parse(s), i.e. exec mode (_annotations.py:232).

Ok(None) is Module(body=[]): an empty or blank source holds no statement at all, and Sphinx’s functools.reduce over node.body then yields the empty node list (_annotations.py:150-151). Ok(Some(e)) is the single Expr statement case, which is what every annotation in the subset is. A top-level Starred — bare (*Ts) or inside a bare tuple (*a, b) — is legal here and is not legal in parse_py_expr.