pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/ac317700ce7439e38a8b420218d9a5035bba92ed

bpo-30406: Make async and await proper keywords (#1669) · python/cpython@ac31770 · GitHub
Skip to content

Commit ac31770

Browse files
JelleZijlstra1st1
authored andcommitted
bpo-30406: Make async and await proper keywords (#1669)
Per PEP 492, 'async' and 'await' should become proper keywords in 3.7.
1 parent 2084b30 commit ac31770

22 files changed

Lines changed: 336 additions & 540 deletions

File tree

Doc/library/token.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ The token constants are:
9898
RARROW
9999
ELLIPSIS
100100
OP
101-
AWAIT
102-
ASYNC
103101
ERRORTOKEN
104102
N_TOKENS
105103
NT_OFFSET
@@ -129,9 +127,11 @@ the :mod:`tokenize` module.
129127

130128

131129
.. versionchanged:: 3.5
132-
Added :data:`AWAIT` and :data:`ASYNC` tokens. Starting with
133-
Python 3.7, "async" and "await" will be tokenized as :data:`NAME`
134-
tokens, and :data:`AWAIT` and :data:`ASYNC` will be removed.
130+
Added :data:`AWAIT` and :data:`ASYNC` tokens.
135131

136132
.. versionchanged:: 3.7
137133
Added :data:`COMMENT`, :data:`NL` and :data:`ENCODING` tokens.
134+
135+
.. versionchanged:: 3.7
136+
Removed :data:`AWAIT` and :data:`ASYNC` tokens. "async" and "await" are
137+
now tokenized as :data:`NAME` tokens.

Doc/tools/extensions/pyspecific.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ def run(self):
272272
# Support for building "topic help" for pydoc
273273

274274
pydoc_topic_labels = [
275-
'assert', 'assignment', 'atom-identifiers', 'atom-literals',
276-
'attribute-access', 'attribute-references', 'augassign', 'binary',
277-
'bitwise', 'bltin-code-objects', 'bltin-ellipsis-object',
275+
'assert', 'assignment', 'async', 'atom-identifiers', 'atom-literals',
276+
'attribute-access', 'attribute-references', 'augassign', 'await',
277+
'binary', 'bitwise', 'bltin-code-objects', 'bltin-ellipsis-object',
278278
'bltin-null-object', 'bltin-type-objects', 'booleans',
279279
'break', 'callable-types', 'calls', 'class', 'comparisons', 'compound',
280280
'context-managers', 'continue', 'conversions', 'customization', 'debugger',

Grammar/Grammar

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
1616
decorators: decorator+
1717
decorated: decorators (classdef | funcdef | async_funcdef)
1818

19-
async_funcdef: ASYNC funcdef
19+
async_funcdef: 'async' funcdef
2020
funcdef: 'def' NAME parameters ['->' test] ':' suite
2121

2222
parameters: '(' [typedargslist] ')'
@@ -68,7 +68,7 @@ nonlocal_stmt: 'nonlocal' NAME (',' NAME)*
6868
assert_stmt: 'assert' test [',' test]
6969

7070
compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated | async_stmt
71-
async_stmt: ASYNC (funcdef | with_stmt | for_stmt)
71+
async_stmt: 'async' (funcdef | with_stmt | for_stmt)
7272
if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
7373
while_stmt: 'while' test ':' suite ['else' ':' suite]
7474
for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
@@ -103,7 +103,7 @@ arith_expr: term (('+'|'-') term)*
103103
term: factor (('*'|'@'|'/'|'%'|'//') factor)*
104104
factor: ('+'|'-'|'~') factor | power
105105
power: atom_expr ['**' factor]
106-
atom_expr: [AWAIT] atom trailer*
106+
atom_expr: ['await'] atom trailer*
107107
atom: ('(' [yield_expr|testlist_comp] ')' |
108108
'[' [testlist_comp] ']' |
109109
'{' [dictorsetmaker] '}' |
@@ -139,7 +139,8 @@ argument: ( test [comp_for] |
139139
'*' test )
140140

141141
comp_iter: comp_for | comp_if
142-
comp_for: [ASYNC] 'for' exprlist 'in' or_test [comp_iter]
142+
sync_comp_for: 'for' exprlist 'in' or_test [comp_iter]
143+
comp_for: ['async'] sync_comp_for
143144
comp_if: 'if' test_nocond [comp_iter]
144145

145146
# not used in grammar, but may appear in "node" passed from Parser to Compiler

Include/graminit.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@
8181
#define arglist 334
8282
#define argument 335
8383
#define comp_iter 336
84-
#define comp_for 337
85-
#define comp_if 338
86-
#define encoding_decl 339
87-
#define yield_expr 340
88-
#define yield_arg 341
84+
#define sync_comp_for 337
85+
#define comp_for 338
86+
#define comp_if 339
87+
#define encoding_decl 340
88+
#define yield_expr 341
89+
#define yield_arg 342

Include/token.h

Lines changed: 59 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,77 +9,75 @@ extern "C" {
99

1010
#undef TILDE /* Prevent clash of our definition with system macro. Ex AIX, ioctl.h */
1111

12-
#define ENDMARKER 0
13-
#define NAME 1
14-
#define NUMBER 2
15-
#define STRING 3
16-
#define NEWLINE 4
17-
#define INDENT 5
18-
#define DEDENT 6
19-
#define LPAR 7
20-
#define RPAR 8
21-
#define LSQB 9
22-
#define RSQB 10
23-
#define COLON 11
24-
#define COMMA 12
25-
#define SEMI 13
26-
#define PLUS 14
27-
#define MINUS 15
28-
#define STAR 16
29-
#define SLASH 17
30-
#define VBAR 18
31-
#define AMPER 19
32-
#define LESS 20
33-
#define GREATER 21
34-
#define EQUAL 22
35-
#define DOT 23
36-
#define PERCENT 24
37-
#define LBRACE 25
38-
#define RBRACE 26
39-
#define EQEQUAL 27
40-
#define NOTEQUAL 28
41-
#define LESSEQUAL 29
42-
#define GREATEREQUAL 30
43-
#define TILDE 31
44-
#define CIRCUMFLEX 32
45-
#define LEFTSHIFT 33
46-
#define RIGHTSHIFT 34
47-
#define DOUBLESTAR 35
48-
#define PLUSEQUAL 36
49-
#define MINEQUAL 37
50-
#define STAREQUAL 38
51-
#define SLASHEQUAL 39
52-
#define PERCENTEQUAL 40
53-
#define AMPEREQUAL 41
54-
#define VBAREQUAL 42
55-
#define CIRCUMFLEXEQUAL 43
56-
#define LEFTSHIFTEQUAL 44
57-
#define RIGHTSHIFTEQUAL 45
58-
#define DOUBLESTAREQUAL 46
59-
#define DOUBLESLASH 47
12+
#define ENDMARKER 0
13+
#define NAME 1
14+
#define NUMBER 2
15+
#define STRING 3
16+
#define NEWLINE 4
17+
#define INDENT 5
18+
#define DEDENT 6
19+
#define LPAR 7
20+
#define RPAR 8
21+
#define LSQB 9
22+
#define RSQB 10
23+
#define COLON 11
24+
#define COMMA 12
25+
#define SEMI 13
26+
#define PLUS 14
27+
#define MINUS 15
28+
#define STAR 16
29+
#define SLASH 17
30+
#define VBAR 18
31+
#define AMPER 19
32+
#define LESS 20
33+
#define GREATER 21
34+
#define EQUAL 22
35+
#define DOT 23
36+
#define PERCENT 24
37+
#define LBRACE 25
38+
#define RBRACE 26
39+
#define EQEQUAL 27
40+
#define NOTEQUAL 28
41+
#define LESSEQUAL 29
42+
#define GREATEREQUAL 30
43+
#define TILDE 31
44+
#define CIRCUMFLEX 32
45+
#define LEFTSHIFT 33
46+
#define RIGHTSHIFT 34
47+
#define DOUBLESTAR 35
48+
#define PLUSEQUAL 36
49+
#define MINEQUAL 37
50+
#define STAREQUAL 38
51+
#define SLASHEQUAL 39
52+
#define PERCENTEQUAL 40
53+
#define AMPEREQUAL 41
54+
#define VBAREQUAL 42
55+
#define CIRCUMFLEXEQUAL 43
56+
#define LEFTSHIFTEQUAL 44
57+
#define RIGHTSHIFTEQUAL 45
58+
#define DOUBLESTAREQUAL 46
59+
#define DOUBLESLASH 47
6060
#define DOUBLESLASHEQUAL 48
6161
#define AT 49
62-
#define ATEQUAL 50
62+
#define ATEQUAL 50
6363
#define RARROW 51
6464
#define ELLIPSIS 52
6565
/* Don't forget to update the table _PyParser_TokenNames in tokenizer.c! */
66-
#define OP 53
67-
#define AWAIT 54
68-
#define ASYNC 55
69-
#define ERRORTOKEN 56
66+
#define OP 53
67+
#define ERRORTOKEN 54
7068
/* These aren't used by the C tokenizer but are needed for tokenize.py */
71-
#define COMMENT 57
72-
#define NL 58
73-
#define ENCODING 59
74-
#define N_TOKENS 60
69+
#define COMMENT 55
70+
#define NL 56
71+
#define ENCODING 57
72+
#define N_TOKENS 58
7573

7674
/* Special definitions for cooperation with parser */
7775

78-
#define NT_OFFSET 256
76+
#define NT_OFFSET 256
7977

80-
#define ISTERMINAL(x) ((x) < NT_OFFSET)
81-
#define ISNONTERMINAL(x) ((x) >= NT_OFFSET)
82-
#define ISEOF(x) ((x) == ENDMARKER)
78+
#define ISTERMINAL(x) ((x) < NT_OFFSET)
79+
#define ISNONTERMINAL(x) ((x) >= NT_OFFSET)
80+
#define ISEOF(x) ((x) == ENDMARKER)
8381

8482

8583
PyAPI_DATA(const char *) _PyParser_TokenNames[]; /* Token names */

Lib/keyword.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
'and',
2121
'as',
2222
'assert',
23+
'async',
24+
'await',
2325
'break',
2426
'class',
2527
'continue',

Lib/lib2to3/Grammar.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ eval_input: testlist NEWLINE* ENDMARKER
3434
decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
3535
decorators: decorator+
3636
decorated: decorators (classdef | funcdef | async_funcdef)
37-
async_funcdef: ASYNC funcdef
37+
async_funcdef: 'async' funcdef
3838
funcdef: 'def' NAME parameters ['->' test] ':' suite
3939
parameters: '(' [typedargslist] ')'
4040
typedargslist: ((tfpdef ['=' test] ',')*
@@ -85,7 +85,7 @@ exec_stmt: 'exec' expr ['in' test [',' test]]
8585
assert_stmt: 'assert' test [',' test]
8686

8787
compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated | async_stmt
88-
async_stmt: ASYNC (funcdef | with_stmt | for_stmt)
88+
async_stmt: 'async' (funcdef | with_stmt | for_stmt)
8989
if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite]
9090
while_stmt: 'while' test ':' suite ['else' ':' suite]
9191
for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
@@ -124,7 +124,7 @@ shift_expr: arith_expr (('<<'|'>>') arith_expr)*
124124
arith_expr: term (('+'|'-') term)*
125125
term: factor (('*'|'@'|'/'|'%'|'//') factor)*
126126
factor: ('+'|'-'|'~') factor | power
127-
power: [AWAIT] atom trailer* ['**' factor]
127+
power: ['await'] atom trailer* ['**' factor]
128128
atom: ('(' [yield_expr|testlist_gexp] ')' |
129129
'[' [listmaker] ']' |
130130
'{' [dictsetmaker] '}' |
@@ -161,7 +161,7 @@ argument: ( test [comp_for] |
161161
star_expr )
162162

163163
comp_iter: comp_for | comp_if
164-
comp_for: [ASYNC] 'for' exprlist 'in' or_test [comp_iter]
164+
comp_for: ['async'] 'for' exprlist 'in' or_test [comp_iter]
165165
comp_if: 'if' old_test [comp_iter]
166166

167167
# As noted above, testlist_safe extends the syntax allowed in list
@@ -180,7 +180,7 @@ comp_if: 'if' old_test [comp_iter]
180180
#
181181
# See https://bugs.python.org/issue27494
182182
old_comp_iter: old_comp_for | old_comp_if
183-
old_comp_for: [ASYNC] 'for' exprlist 'in' testlist_safe [old_comp_iter]
183+
old_comp_for: ['async'] 'for' exprlist 'in' testlist_safe [old_comp_iter]
184184
old_comp_if: 'if' old_test [old_comp_iter]
185185

186186
testlist1: test (',' test)*

Lib/lib2to3/pgen2/token.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@
6262
COMMENT = 53
6363
NL = 54
6464
RARROW = 55
65-
AWAIT = 56
66-
ASYNC = 57
67-
ERRORTOKEN = 58
68-
N_TOKENS = 59
65+
ERRORTOKEN = 56
66+
N_TOKENS = 57
6967
NT_OFFSET = 256
7068
#--end constants--
7169

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy