Skip to content

Commit

Permalink
Allow same RHS expressions in annotated assignments as in regular ass…
Browse files Browse the repository at this point in the history
…ignments
  • Loading branch information
ichard26 committed Nov 23, 2020
1 parent dea81b7 commit c195d3e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.md
Expand Up @@ -21,6 +21,9 @@

- Added support for PEP 614 relaxed decorator syntax on python 3.9 (#1711)

- Added parsing support for unparenthesized tuples and yield expressions in annotated
assignments (#1835)

- use lowercase hex strings (#1692)

#### _Packaging_
Expand Down
2 changes: 1 addition & 1 deletion src/blib2to3/Grammar.txt
Expand Up @@ -77,7 +77,7 @@ small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt |
import_stmt | global_stmt | exec_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_star_expr)]
testlist_star_expr: (test|star_expr) (',' (test|star_expr))* [',']
augassign: ('+=' | '-=' | '*=' | '@=' | '/=' | '%=' | '&=' | '|=' | '^=' |
'<<=' | '>>=' | '**=' | '//=')
Expand Down
18 changes: 18 additions & 0 deletions tests/data/python38.py
Expand Up @@ -11,6 +11,14 @@ def starred_yield():
yield "value1", *my_list


# all right hand side expressions allowed in regular assignments are now also allowed in
# annotated assignments
a : Tuple[ str, int] = "1", 2
a: Tuple[int , ... ] = b, *c, d
def t():
a : str = yield "a"


# output


Expand All @@ -25,3 +33,13 @@ def starred_return():
def starred_yield():
my_list = ["value2", "value3"]
yield "value1", *my_list


# all right hand side expressions allowed in regular assignments are now also allowed in
# annotated assignments
a: Tuple[str, int] = "1", 2
a: Tuple[int, ...] = b, *c, d


def t():
a: str = yield "a"

0 comments on commit c195d3e

Please sign in to comment.