Unverified Commit 366a0806 authored by Richard Si's avatar Richard Si Committed by GitHub
Browse files

blib2to3: support unparenthesized wulruses in more places (#2447)


Implementation stolen from PR davidhalter/parso#162. Thanks parso!

I could add support for these newer syntactical constructs in the
target version detection logic, but until I get diff-shades up
and running I don't feel very comfortable adding the code.
parent 8a59528c
Loading
Loading
Loading
Loading
+2 −0
Changes for CHANGES.md: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@
  hardened to handle more edge cases during quote normalization (#2437)
- Avoid changing a function return type annotation's type to a tuple by adding a
  trailing comma (#2384)
- Parsing support has been added for unparenthesized walruses in set literals, set
  comprehensions, and indices (#2447).

### _Blackd_

+3 −3
Changes for src/blib2to3/Grammar.txt: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -157,14 +157,14 @@ testlist_gexp: (namedexpr_test|star_expr) ( old_comp_for | (',' (namedexpr_test|
lambdef: 'lambda' [varargslist] ':' test
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
subscriptlist: subscript (',' subscript)* [',']
subscript: test | [test] ':' [test] [sliceop]
subscript: test [':=' test] | [test] ':' [test] [sliceop]
sliceop: ':' [test]
exprlist: (expr|star_expr) (',' (expr|star_expr))* [',']
testlist: test (',' test)* [',']
dictsetmaker: ( ((test ':' test | '**' expr)
                 (comp_for | (',' (test ':' test | '**' expr))* [','])) |
                ((test | star_expr)
		 (comp_for | (',' (test | star_expr))* [','])) )
                ((test [':=' test] | star_expr)
		 (comp_for | (',' (test [':=' test] | star_expr))* [','])) )

classdef: 'class' NAME ['(' [arglist] ')'] ':' suite

+5 −0
Changes for src/blib2to3/README: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -14,3 +14,8 @@ Reasons for forking:

Change Log:
- Changes default logger used by Driver
- Backported the following upstream parser changes:
  - "bpo-42381: Allow walrus in set literals and set comprehensions (GH-23332)"
    https://github.com/python/cpython/commit/cae60187cf7a7b26281d012e1952fafe4e2e97e9
  - "bpo-42316: Allow unparenthesized walrus operator in indexes (GH-23317)"
    https://github.com/python/cpython/commit/b0aba1fcdc3da952698d99aec2334faa79a8b68c
+4 −0
Changes for tests/data/pep_572_py310.py: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Unparenthesized walruses are now allowed in indices since Python 3.10.
x[a:=0]
x[a:=0, b:=1]
x[5, b:=0]
+7 −0
Changes for tests/data/pep_572_py39.py: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Unparenthesized walruses are now allowed in set literals & set comprehensions
# since Python 3.9
{x := 1, 2, 3}
{x4 := x ** 5 for x in range(7)}
# We better not remove the parentheses here (since it's a 3.10 feature)
x[(a := 1)]
x[(a := 1), (b := 3)]
Loading