diff options
author | Tim Hatch <tim@timhatch.com> | 2020-04-02 22:34:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-02 22:34:54 (GMT) |
commit | 3c3aa4516c70753de06bb142b6793d01330fcf0f (patch) | |
tree | cea6e6cc2cfc646d8ff84aff0c5bf596417e598c /Lib/lib2to3/pgen2 | |
parent | 45217af29c7f380089af17beb48a5ea0560bbb9d (diff) | |
download | cpython-3c3aa4516c70753de06bb142b6793d01330fcf0f.zip cpython-3c3aa4516c70753de06bb142b6793d01330fcf0f.tar.gz cpython-3c3aa4516c70753de06bb142b6793d01330fcf0f.tar.bz2 |
lib2to3: Support named assignment expressions (GH-12702)
There are two copies of the grammar -- the one used by Python itself as
Grammar/Grammar, and the one used by lib2to3 which has necessarily diverged at
Lib/lib2to3/Grammar.txt because it needs to support older syntax an we want it
to be reasonable stable to avoid requiring fixer rewrites.
This brings suport for syntax like `if x:= foo():` to match what the live
Python grammar does.
This should've been added at the time of the walrus operator itself, but lib2to3 being
independent is often overlooked. So we do consider this a bugfix rather than enhancement.
Diffstat (limited to 'Lib/lib2to3/pgen2')
-rw-r--r-- | Lib/lib2to3/pgen2/grammar.py | 1 | ||||
-rwxr-xr-x | Lib/lib2to3/pgen2/token.py | 3 | ||||
-rw-r--r-- | Lib/lib2to3/pgen2/tokenize.py | 2 |
3 files changed, 4 insertions, 2 deletions
diff --git a/Lib/lib2to3/pgen2/grammar.py b/Lib/lib2to3/pgen2/grammar.py index a1da546..6a4d575 100644 --- a/Lib/lib2to3/pgen2/grammar.py +++ b/Lib/lib2to3/pgen2/grammar.py @@ -178,6 +178,7 @@ opmap_raw = """ // DOUBLESLASH //= DOUBLESLASHEQUAL -> RARROW +:= COLONEQUAL """ opmap = {} diff --git a/Lib/lib2to3/pgen2/token.py b/Lib/lib2to3/pgen2/token.py index 1a67955..5f6612f 100755 --- a/Lib/lib2to3/pgen2/token.py +++ b/Lib/lib2to3/pgen2/token.py @@ -65,7 +65,8 @@ RARROW = 55 AWAIT = 56 ASYNC = 57 ERRORTOKEN = 58 -N_TOKENS = 59 +COLONEQUAL = 59 +N_TOKENS = 60 NT_OFFSET = 256 #--end constants-- diff --git a/Lib/lib2to3/pgen2/tokenize.py b/Lib/lib2to3/pgen2/tokenize.py index 7924ff3..0e2685d 100644 --- a/Lib/lib2to3/pgen2/tokenize.py +++ b/Lib/lib2to3/pgen2/tokenize.py @@ -93,7 +93,7 @@ Operator = group(r"\*\*=?", r">>=?", r"<<=?", r"<>", r"!=", r"~") Bracket = '[][(){}]' -Special = group(r'\r?\n', r'[:;.,`@]') +Special = group(r'\r?\n', r':=', r'[:;.,`@]') Funny = group(Operator, Bracket, Special) PlainToken = group(Number, Funny, String, Name) |