unpacking + py35+ *splat: SyntaxError: can't use starred expression here

Issue #2995 resolved
Anthony Sottile created an issue

Here's sample code which works correctly in cpython 3.5+

def f(*args):
    if len(args) == 1:
        x, y = (0, *args)
    elif len(args) == 2:
        x, y = args
    else:
        raise TypeError('{} {!r}'.format(len(args), args))

    print(x, y)

f(1)
f(1, 2)
f(1, 2, 3)

Here's the expected output in python3.5:

$ python3.5 t2.py
0 1
1 2
Traceback (most recent call last):
  File "t2.py", line 13, in <module>
    f(1, 2, 3)
  File "t2.py", line 7, in f
    raise TypeError('{} {!r}'.format(len(args), args))
TypeError: 3 (1, 2, 3)

pypy3.5 (and pypy3.6) reject this code with a SyntaxError:

$ ./pypy3.6-v7.1.0-linux64/bin/pypy3 --version
Python 3.6.1 (de061d87e39c, Mar 24 2019, 22:18:07)
[PyPy 7.1.0-beta0 with GCC 6.2.0 20160901]
$ pypy3 --version
Python 3.5.3 (fdd60ed87e94, Apr 24 2018, 06:10:04)
[PyPy 6.0.0 with GCC 6.2.0 20160901]
$ ./pypy3.6-v7.1.0-linux64/bin/pypy3 t2.py
  File "t2.py", line 3
    x, y = (0, *args)
              ^
SyntaxError: can't use starred expression here
$ pypy3 t2.py
  File "t2.py", line 3
    x, y = (0, *args)
              ^
SyntaxError: can't use starred expression here

Here's a much smaller reproduction:

x = (1,)
a, b = (*x, 2)

Comments (2)

  1. Log in to comment