Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
62c35a8a
Commit
62c35a8a
authored
Jan 25, 2019
by
Ivan Levkivskyi
Committed by
GitHub
Jan 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-35814: Allow same r.h.s. in annotated assignments as in normal ones (GH-11667)
parent
1396d8fa
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
23 additions
and
6 deletions
+23
-6
Grammar/Grammar
Grammar/Grammar
+1
-1
Lib/test/test_grammar.py
Lib/test/test_grammar.py
+9
-0
Lib/test/test_parser.py
Lib/test/test_parser.py
+1
-1
Misc/NEWS.d/next/Core and Builtins/2019-01-24-13-25-21.bpo-35814.r_MjA6.rst
...ore and Builtins/2019-01-24-13-25-21.bpo-35814.r_MjA6.rst
+2
-0
Python/ast.c
Python/ast.c
+6
-1
Python/graminit.c
Python/graminit.c
+4
-3
No files found.
Grammar/Grammar
View file @
62c35a8a
...
...
@@ -40,7 +40,7 @@ small_stmt: (expr_stmt | del_stmt | pass_stmt | flow_stmt |
import_stmt | global_stmt | nonlocal_stmt | assert_stmt)
expr_stmt: testlist_star_expr (annassign | augassign (yield_expr|testlist) |
('=' (yield_expr|testlist_star_expr))*)
annassign: ':' test ['='
test
]
annassign: ':' test ['='
(yield_expr|testlist)
]
testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']
augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' |
'<<=' | '>>=' | '**=' | '//=')
...
...
Lib/test/test_grammar.py
View file @
62c35a8a
...
...
@@ -445,6 +445,15 @@ class GrammarTests(unittest.TestCase):
exec
(
'X: str'
,
{},
CNS2
())
self
.
assertEqual
(
nonloc_ns
[
'__annotations__'
][
'x'
],
str
)
def
test_var_annot_rhs
(
self
):
ns
=
{}
exec
(
'x: tuple = 1, 2'
,
ns
)
self
.
assertEqual
(
ns
[
'x'
],
(
1
,
2
))
stmt
=
(
'def f():
\
n
'
' x: int = yield'
)
exec
(
stmt
,
ns
)
self
.
assertEqual
(
list
(
ns
[
'f'
]()),
[
None
])
def
test_funcdef
(
self
):
### [decorators] 'def' NAME parameters ['->' test] ':' suite
### decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
...
...
Lib/test/test_parser.py
View file @
62c35a8a
...
...
@@ -166,7 +166,7 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase):
with
self
.
assertRaises
(
SyntaxError
):
exec
(
"x, *y, z: int = range(5)"
,
{},
{})
with
self
.
assertRaises
(
SyntaxError
):
exec
(
"
t: tuple = 1,
2"
,
{},
{})
exec
(
"
x: int = 1, y =
2"
,
{},
{})
with
self
.
assertRaises
(
SyntaxError
):
exec
(
"u = v: int"
,
{},
{})
with
self
.
assertRaises
(
SyntaxError
):
...
...
Misc/NEWS.d/next/Core and Builtins/2019-01-24-13-25-21.bpo-35814.r_MjA6.rst
0 → 100644
View file @
62c35a8a
Allow same right hand side expressions in annotated assignments as in normal ones.
In particular, ``x: Tuple[int, int] = 1, 2`` (without parentheses on the right) is now allowed.
\ No newline at end of file
Python/ast.c
View file @
62c35a8a
...
...
@@ -3163,7 +3163,12 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
}
else
{
ch
=
CHILD
(
ann
,
3
);
expr3
=
ast_for_expr
(
c
,
ch
);
if
(
TYPE
(
ch
)
==
testlist
)
{
expr3
=
ast_for_testlist
(
c
,
ch
);
}
else
{
expr3
=
ast_for_expr
(
c
,
ch
);
}
if
(
!
expr3
)
{
return
NULL
;
}
...
...
Python/graminit.c
View file @
62c35a8a
...
...
@@ -498,8 +498,9 @@ static arc arcs_17_2[2] = {
{
31
,
3
},
{
0
,
2
},
};
static
arc
arcs_17_3
[
1
]
=
{
{
26
,
4
},
static
arc
arcs_17_3
[
2
]
=
{
{
50
,
4
},
{
9
,
4
},
};
static
arc
arcs_17_4
[
1
]
=
{
{
0
,
4
},
...
...
@@ -508,7 +509,7 @@ static state states_17[5] = {
{
1
,
arcs_17_0
},
{
1
,
arcs_17_1
},
{
2
,
arcs_17_2
},
{
1
,
arcs_17_3
},
{
2
,
arcs_17_3
},
{
1
,
arcs_17_4
},
};
static
arc
arcs_18_0
[
2
]
=
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment