1e99d29f36
This is a partial implementation of PEP 448 to allow multiple ** unpackings when calling a function or method. The compiler is modified to encode the argument as a None: obj key-value pair (similar to how regular keyword arguments are encoded as str: obj pairs). The extra object that was pushed on the stack to hold a single ** unpacking object is no longer used and is removed. The runtime is modified to decode this new format. Signed-off-by: David Lechner <david@pybricks.com>
34 lines
566 B
Python
34 lines
566 B
Python
# test calling a function with multiple **args
|
|
|
|
|
|
def f(a, b=None, c=None):
|
|
print(a, b, c)
|
|
|
|
|
|
f(**{"a": 1}, **{"b": 2})
|
|
f(**{"a": 1}, **{"b": 2}, c=3)
|
|
f(**{"a": 1}, b=2, **{"c": 3})
|
|
|
|
try:
|
|
f(1, **{"b": 2}, **{"b": 3})
|
|
except TypeError:
|
|
print("TypeError")
|
|
|
|
# test calling a method with multiple **args
|
|
|
|
|
|
class A:
|
|
def f(self, a, b=None, c=None):
|
|
print(a, b, c)
|
|
|
|
|
|
a = A()
|
|
a.f(**{"a": 1}, **{"b": 2})
|
|
a.f(**{"a": 1}, **{"b": 2}, c=3)
|
|
a.f(**{"a": 1}, b=2, **{"c": 3})
|
|
|
|
try:
|
|
a.f(1, **{"b": 2}, **{"b": 3})
|
|
except TypeError:
|
|
print("TypeError")
|