Skip to content

Commit 114ceba

Browse files
authored
Add Documentation for Python 3.9 AST changes (#201)
* Editorconf * Cleanup travis-ci * changes to 3.9
1 parent 5fb5b16 commit 114ceba

File tree

6 files changed

+187
-11
lines changed

6 files changed

+187
-11
lines changed

.editorconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,10 @@ indent_size = 2
3434
indent_style = tab
3535
indent_size = unset
3636
tab_width = unset
37+
38+
[*.bat]
39+
indent_style = tab
40+
end_of_line = crlf
41+
42+
[LICENSE]
43+
insert_final_newline = false

.travis.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ matrix:
55
- name: "coding-conventions & docs"
66
python: "3.6"
77
env: TOXENV=docs,lint
8-
before_install:
98
after_success:
109
- python: "2.7"
1110
env: TOXENV=py27,py27-datetime
@@ -19,13 +18,11 @@ matrix:
1918
env: TOXENV=py38,py38-datetime
2019
- python: "3.9-dev"
2120
env: TOXENV=py39,py39-datetime
22-
23-
before_install:
24-
- travis_retry pip install -U -c constraints.txt coveralls coverage
21+
# - python: "3.10-dev"
22+
# env: TOXENV=py310,py310-datetime
2523

2624
install:
27-
- travis_retry pip install -U pip setuptools
28-
- travis_retry pip install -U -c constraints.txt tox
25+
- travis_retry pip install -U -c constraints.txt pip setuptools coveralls coverage tox
2926

3027
script:
3128
- travis_retry tox

docs/contributing/ast/python3_9.ast

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
-- Python 3.9 AST
2+
-- ASDL's 4 builtin types are:
3+
-- identifier, int, string, constant
4+
5+
module Python version "3.9"
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+
| Raise(expr? exc, expr? cause)
47+
| Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)
48+
| Assert(expr test, expr? msg)
49+
50+
| Import(alias* names)
51+
| ImportFrom(identifier? module, alias* names, int? level)
52+
53+
| Global(identifier* names)
54+
| Nonlocal(identifier* names)
55+
| Expr(expr value)
56+
| Pass
57+
| Break
58+
| Continue
59+
60+
-- col_offset is the byte offset in the utf8 string the parser uses
61+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
62+
63+
-- BoolOp() can use left & right?
64+
expr = BoolOp(boolop op, expr* values)
65+
| NamedExpr(expr target, expr value)
66+
| BinOp(expr left, operator op, expr right)
67+
| UnaryOp(unaryop op, expr operand)
68+
| Lambda(arguments args, expr body)
69+
| IfExp(expr test, expr body, expr orelse)
70+
| Dict(expr* keys, expr* values)
71+
| Set(expr* elts)
72+
| ListComp(expr elt, comprehension* generators)
73+
| SetComp(expr elt, comprehension* generators)
74+
| DictComp(expr key, expr value, comprehension* generators)
75+
| GeneratorExp(expr elt, comprehension* generators)
76+
-- the grammar constrains where yield expressions can occur
77+
| Await(expr value)
78+
| Yield(expr? value)
79+
| YieldFrom(expr value)
80+
-- need sequences for compare to distinguish between
81+
-- x < 4 < 3 and (x < 4) < 3
82+
| Compare(expr left, cmpop* ops, expr* comparators)
83+
| Call(expr func, expr* args, keyword* keywords)
84+
| FormattedValue(expr value, int? conversion, expr? format_spec)
85+
| JoinedStr(expr* values)
86+
| Constant(constant value, string? kind)
87+
88+
-- the following expression can appear in assignment context
89+
| Attribute(expr value, identifier attr, expr_context ctx)
90+
| Subscript(expr value, expr slice, expr_context ctx)
91+
| Starred(expr value, expr_context ctx)
92+
| Name(identifier id, expr_context ctx)
93+
| List(expr* elts, expr_context ctx)
94+
| Tuple(expr* elts, expr_context ctx)
95+
96+
-- can appear only in Subscript
97+
| Slice(expr? lower, expr? upper, expr? step)
98+
99+
-- col_offset is the byte offset in the utf8 string the parser uses
100+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
101+
102+
expr_context = Load
103+
| Store
104+
| Del
105+
106+
boolop = And
107+
| Or
108+
109+
operator = Add
110+
| Sub
111+
| Mult
112+
| MatMult
113+
| Div
114+
| Mod
115+
| Pow
116+
| LShift
117+
| RShift
118+
| BitOr
119+
| BitXor
120+
| BitAnd
121+
| FloorDiv
122+
123+
unaryop = Invert
124+
| Not
125+
| UAdd
126+
| USub
127+
128+
cmpop = Eq
129+
| NotEq
130+
| Lt
131+
| LtE
132+
| Gt
133+
| GtE
134+
| Is
135+
| IsNot
136+
| In
137+
| NotIn
138+
139+
comprehension = (expr target, expr iter, expr* ifs, int is_async)
140+
141+
excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)
142+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
143+
144+
arguments = (arg* posonlyargs,
145+
arg* args,
146+
arg? vararg,
147+
arg* kwonlyargs,
148+
expr* kw_defaults,
149+
arg? kwarg,
150+
expr* defaults)
151+
152+
arg = (identifier arg, expr? annotation, string? type_comment)
153+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
154+
155+
-- keyword arguments supplied to call (NULL identifier for **kwargs)
156+
keyword = (identifier? arg, expr value)
157+
attributes (int lineno, int col_offset, int? end_lineno, int? end_col_offset)
158+
159+
-- import name with optional 'as' alias.
160+
alias = (identifier name, identifier? asname)
161+
162+
withitem = (expr context_expr, expr? optional_vars)
163+
164+
type_ignore = TypeIgnore(int lineno, string tag)
165+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Changes from Python 3.8 to Python 3.9
2+
-------------------------------------
3+
4+
.. literalinclude:: ast/python3_9.ast
5+
:diff: ast/python3_8.ast

docs/contributing/index.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ Technical Backgrounds - Links to External Documentation
6161

6262
* AST Grammar of Python
6363

64+
* `Python 3.9 AST`_
6465
* `Python 3.8 AST`_
6566
* `Python 3.7 AST`_
6667
* `Python 3.6 AST`_
67-
* `Python 3.5 AST`_
68+
* `Python 3.5 AST`_ (becoming obsolete)
6869
* `Python 3.4 AST`_ (obsolete)
6970
* `Python 3.3 AST`_ (obsolete)
7071
* `Python 3.2 AST`_ (obsolete)
@@ -73,9 +74,9 @@ Technical Backgrounds - Links to External Documentation
7374
* `Python 2.7 AST`_
7475
* `Python 2.6 AST`_ (obsolete)
7576

76-
* `AST NodeVistiors Class`_ (https://docs.python.org/3.5/library/ast.html#ast.NodeVisitor)
77-
* `AST NodeTransformer Class`_ (https://docs.python.org/3.5/library/ast.html#ast.NodeTransformer)
78-
* `AST dump method`_ (https://docs.python.org/3.5/library/ast.html#ast.dump)
77+
* `AST NodeVistiors Class`_ (https://docs.python.org/3.9/library/ast.html#ast.NodeVisitor)
78+
* `AST NodeTransformer Class`_ (https://docs.python.org/3.9/library/ast.html#ast.NodeTransformer)
79+
* `AST dump method`_ (https://docs.python.org/3.9/library/ast.html#ast.dump)
7980

8081
* `In detail Documentation on the Python AST module (Green Tree Snakes)`_
8182
* `Example how to Instrumenting the Python AST`_
@@ -97,7 +98,7 @@ A (modified style) Copy of all Abstract Grammar Definitions for the Python versi
9798
changes_from35to36
9899
changes_from36to37
99100
changes_from37to38
100-
101+
changes_from38to39
101102

102103
.. Links
103104

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ envlist =
77
py37,
88
py38,
99
py39,
10+
#py310,
1011
docs,
1112
lint,
1213
coverage,

0 commit comments

Comments
 (0)