Skip to content

Commit 582ebd4

Browse files
authored
Update Python 3.10 & 3.11 documentation --> ast (#236)
Update compared ast files and links to ast origin. Updated Roadmap document, so that it matches really done work.
1 parent 69b774f commit 582ebd4

File tree

6 files changed

+395
-10
lines changed

6 files changed

+395
-10
lines changed

docs/contributing/ast/python3_10.ast

+184
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
-- Python 3.10 AST
2+
-- ASDL's 4 builtin types are:
3+
-- identifier, int, string, constant
4+
5+
module Python version "3.10"
6+
{
7+
mod = Module(stmt* body, type_ignore* type_ignores)
8+
| Interactive(stmt* body)
9+
| Expression(expr body)
10+
| FunctionType(expr* argtypes, expr returns)
11+
12+
stmt = FunctionDef(identifier name,
13+
arguments args,
14+
stmt* body,
15+
expr* decorator_list,
16+
expr? returns,
17+
string? type_comment)
18+
| AsyncFunctionDef(identifier name,
19+
arguments args,
20+
stmt* body,
21+
expr* decorator_list,
22+
expr? returns,
23+
string? type_comment)
24+
25+
| ClassDef(identifier name,
26+
expr* bases,
27+
keyword* keywords,
28+
stmt* body,
29+
expr* decorator_list)
30+
| Return(expr? value)
31+
32+
| Delete(expr* targets)
33+
| Assign(expr* targets, expr value, string? type_comment)
34+
| AugAssign(expr target, operator op, expr value)
35+
-- 'simple' indicates that we annotate simple name without parens
36+
| AnnAssign(expr target, expr annotation, expr? value, int simple)
37+
38+
-- use 'orelse' because else is a keyword in target languages
39+
| For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)
40+
| AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)
41+
| While(expr test, stmt* body, stmt* orelse)
42+
| If(expr test, stmt* body, stmt* orelse)
43+
| With(withitem* items, stmt* body, string? type_comment)
44+
| AsyncWith(withitem* items, stmt* body, string? type_comment)
45+
46+
| Match(expr subject, match_case* cases)
47+
48+
| Raise(expr? exc, expr? cause)
49+
| Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
50+
| Assert(expr test, expr? msg)
51+
52+
| Import(alias* names)
53+
| ImportFrom(identifier? module, alias* names, int? level)
54+
55+
| Global(identifier* names)
56+
| Nonlocal(identifier* names)
57+
| Expr(expr value)
58+
| Pass
59+
| Break
60+
| Continue
61+
62+
-- col_offset is the byte offset in the utf8 string the parser uses
63+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
64+
65+
-- BoolOp() can use left & right?
66+
expr = BoolOp(boolop op, expr* values)
67+
| NamedExpr(expr target, expr value)
68+
| BinOp(expr left, operator op, expr right)
69+
| UnaryOp(unaryop op, expr operand)
70+
| Lambda(arguments args, expr body)
71+
| IfExp(expr test, expr body, expr orelse)
72+
| Dict(expr* keys, expr* values)
73+
| Set(expr* elts)
74+
| ListComp(expr elt, comprehension* generators)
75+
| SetComp(expr elt, comprehension* generators)
76+
| DictComp(expr key, expr value, comprehension* generators)
77+
| GeneratorExp(expr elt, comprehension* generators)
78+
-- the grammar constrains where yield expressions can occur
79+
| Await(expr value)
80+
| Yield(expr? value)
81+
| YieldFrom(expr value)
82+
-- need sequences for compare to distinguish between
83+
-- x < 4 < 3 and (x < 4) < 3
84+
| Compare(expr left, cmpop* ops, expr* comparators)
85+
| Call(expr func, expr* args, keyword* keywords)
86+
| FormattedValue(expr value, int conversion, expr? format_spec)
87+
| JoinedStr(expr* values)
88+
| Constant(constant value, string? kind)
89+
90+
-- the following expression can appear in assignment context
91+
| Attribute(expr value, identifier attr, expr_context ctx)
92+
| Subscript(expr value, expr slice, expr_context ctx)
93+
| Starred(expr value, expr_context ctx)
94+
| Name(identifier id, expr_context ctx)
95+
| List(expr* elts, expr_context ctx)
96+
| Tuple(expr* elts, expr_context ctx)
97+
98+
-- can appear only in Subscript
99+
| Slice(expr? lower, expr? upper, expr? step)
100+
101+
-- col_offset is the byte offset in the utf8 string the parser uses
102+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
103+
104+
expr_context = Load
105+
| Store
106+
| Del
107+
108+
boolop = And
109+
| Or
110+
111+
operator = Add
112+
| Sub
113+
| Mult
114+
| MatMult
115+
| Div
116+
| Mod
117+
| Pow
118+
| LShift
119+
| RShift
120+
| BitOr
121+
| BitXor
122+
| BitAnd
123+
| FloorDiv
124+
125+
unaryop = Invert
126+
| Not
127+
| UAdd
128+
| USub
129+
130+
cmpop = Eq
131+
| NotEq
132+
| Lt
133+
| LtE
134+
| Gt
135+
| GtE
136+
| Is
137+
| IsNot
138+
| In
139+
| NotIn
140+
141+
comprehension = (expr target, expr iter, expr* ifs, int is_async)
142+
143+
excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
144+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
145+
146+
arguments = (arg* posonlyargs,
147+
arg* args,
148+
arg? vararg,
149+
arg* kwonlyargs,
150+
expr* kw_defaults,
151+
arg? kwarg,
152+
expr* defaults)
153+
154+
arg = (identifier arg, expr? annotation, string? type_comment)
155+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
156+
157+
-- keyword arguments supplied to call (NULL identifier for **kwargs)
158+
keyword = (identifier? arg, expr value)
159+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
160+
161+
-- import name with optional 'as' alias.
162+
alias = (identifier name, identifier? asname)
163+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
164+
165+
withitem = (expr context_expr, expr? optional_vars)
166+
167+
match_case = (pattern pattern, expr? guard, stmt* body)
168+
169+
pattern = MatchValue(expr value)
170+
| MatchSingleton(constant value)
171+
| MatchSequence(pattern* patterns)
172+
| MatchMapping(expr* keys, pattern* patterns, identifier? rest)
173+
| MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)
174+
175+
| MatchStar(identifier? name)
176+
-- The optional "rest" MatchMapping parameter handles capturing extra mapping keys
177+
178+
| MatchAs(pattern? pattern, identifier? name)
179+
| MatchOr(pattern* patterns)
180+
181+
attributes (int lineno, int col_offset, int end_lineno, int end_col_offset)
182+
183+
type_ignore = TypeIgnore(int lineno, string tag)
184+
}

docs/contributing/ast/python3_11.ast

+185
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
-- Python 3.11 AST
2+
-- ASDL's 4 builtin types are:
3+
-- identifier, int, string, constant
4+
5+
module Python version "3.11"
6+
{
7+
mod = Module(stmt* body, type_ignore* type_ignores)
8+
| Interactive(stmt* body)
9+
| Expression(expr body)
10+
| FunctionType(expr* argtypes, expr returns)
11+
12+
stmt = FunctionDef(identifier name,
13+
arguments args,
14+
stmt* body,
15+
expr* decorator_list,
16+
expr? returns,
17+
string? type_comment)
18+
| AsyncFunctionDef(identifier name,
19+
arguments args,
20+
stmt* body,
21+
expr* decorator_list,
22+
expr? returns,
23+
string? type_comment)
24+
25+
| ClassDef(identifier name,
26+
expr* bases,
27+
keyword* keywords,
28+
stmt* body,
29+
expr* decorator_list)
30+
| Return(expr? value)
31+
32+
| Delete(expr* targets)
33+
| Assign(expr* targets, expr value, string? type_comment)
34+
| AugAssign(expr target, operator op, expr value)
35+
-- 'simple' indicates that we annotate simple name without parens
36+
| AnnAssign(expr target, expr annotation, expr? value, int simple)
37+
38+
-- use 'orelse' because else is a keyword in target languages
39+
| For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)
40+
| AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)
41+
| While(expr test, stmt* body, stmt* orelse)
42+
| If(expr test, stmt* body, stmt* orelse)
43+
| With(withitem* items, stmt* body, string? type_comment)
44+
| AsyncWith(withitem* items, stmt* body, string? type_comment)
45+
46+
| Match(expr subject, match_case* cases)
47+
48+
| Raise(expr? exc, expr? cause)
49+
| Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
50+
| TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
51+
| Assert(expr test, expr? msg)
52+
53+
| Import(alias* names)
54+
| ImportFrom(identifier? module, alias* names, int? level)
55+
56+
| Global(identifier* names)
57+
| Nonlocal(identifier* names)
58+
| Expr(expr value)
59+
| Pass
60+
| Break
61+
| Continue
62+
63+
-- col_offset is the byte offset in the utf8 string the parser uses
64+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
65+
66+
-- BoolOp() can use left & right?
67+
expr = BoolOp(boolop op, expr* values)
68+
| NamedExpr(expr target, expr value)
69+
| BinOp(expr left, operator op, expr right)
70+
| UnaryOp(unaryop op, expr operand)
71+
| Lambda(arguments args, expr body)
72+
| IfExp(expr test, expr body, expr orelse)
73+
| Dict(expr* keys, expr* values)
74+
| Set(expr* elts)
75+
| ListComp(expr elt, comprehension* generators)
76+
| SetComp(expr elt, comprehension* generators)
77+
| DictComp(expr key, expr value, comprehension* generators)
78+
| GeneratorExp(expr elt, comprehension* generators)
79+
-- the grammar constrains where yield expressions can occur
80+
| Await(expr value)
81+
| Yield(expr? value)
82+
| YieldFrom(expr value)
83+
-- need sequences for compare to distinguish between
84+
-- x < 4 < 3 and (x < 4) < 3
85+
| Compare(expr left, cmpop* ops, expr* comparators)
86+
| Call(expr func, expr* args, keyword* keywords)
87+
| FormattedValue(expr value, int conversion, expr? format_spec)
88+
| JoinedStr(expr* values)
89+
| Constant(constant value, string? kind)
90+
91+
-- the following expression can appear in assignment context
92+
| Attribute(expr value, identifier attr, expr_context ctx)
93+
| Subscript(expr value, expr slice, expr_context ctx)
94+
| Starred(expr value, expr_context ctx)
95+
| Name(identifier id, expr_context ctx)
96+
| List(expr* elts, expr_context ctx)
97+
| Tuple(expr* elts, expr_context ctx)
98+
99+
-- can appear only in Subscript
100+
| Slice(expr? lower, expr? upper, expr? step)
101+
102+
-- col_offset is the byte offset in the utf8 string the parser uses
103+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
104+
105+
expr_context = Load
106+
| Store
107+
| Del
108+
109+
boolop = And
110+
| Or
111+
112+
operator = Add
113+
| Sub
114+
| Mult
115+
| MatMult
116+
| Div
117+
| Mod
118+
| Pow
119+
| LShift
120+
| RShift
121+
| BitOr
122+
| BitXor
123+
| BitAnd
124+
| FloorDiv
125+
126+
unaryop = Invert
127+
| Not
128+
| UAdd
129+
| USub
130+
131+
cmpop = Eq
132+
| NotEq
133+
| Lt
134+
| LtE
135+
| Gt
136+
| GtE
137+
| Is
138+
| IsNot
139+
| In
140+
| NotIn
141+
142+
comprehension = (expr target, expr iter, expr* ifs, int is_async)
143+
144+
excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
145+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
146+
147+
arguments = (arg* posonlyargs,
148+
arg* args,
149+
arg? vararg,
150+
arg* kwonlyargs,
151+
expr* kw_defaults,
152+
arg? kwarg,
153+
expr* defaults)
154+
155+
arg = (identifier arg, expr? annotation, string? type_comment)
156+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
157+
158+
-- keyword arguments supplied to call (NULL identifier for **kwargs)
159+
keyword = (identifier? arg, expr value)
160+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
161+
162+
-- import name with optional 'as' alias.
163+
alias = (identifier name, identifier? asname)
164+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
165+
166+
withitem = (expr context_expr, expr? optional_vars)
167+
168+
match_case = (pattern pattern, expr? guard, stmt* body)
169+
170+
pattern = MatchValue(expr value)
171+
| MatchSingleton(constant value)
172+
| MatchSequence(pattern* patterns)
173+
| MatchMapping(expr* keys, pattern* patterns, identifier? rest)
174+
| MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)
175+
176+
| MatchStar(identifier? name)
177+
-- The optional "rest" MatchMapping parameter handles capturing extra mapping keys
178+
179+
| MatchAs(pattern? pattern, identifier? name)
180+
| MatchOr(pattern* patterns)
181+
182+
attributes (int lineno, int col_offset, int end_lineno, int end_col_offset)
183+
184+
type_ignore = TypeIgnore(int lineno, string tag)
185+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Changes from Python 3.10 to Python 3.11
2+
-------------------------------------
3+
4+
.. literalinclude:: ast/python3_11.ast
5+
:diff: ast/python3_10.ast
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Changes from Python 3.9 to Python 3.10
2+
-------------------------------------
3+
4+
.. literalinclude:: ast/python3_10.ast
5+
:diff: ast/python3_9.ast

0 commit comments

Comments
 (0)