mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 11:10:14 +01:00
This fixes code coverage for the case where a *arg without __len__ is unpacked and uses exactly the amount of memory that was allocated for kw args. This triggers the code branch where the memory for the kw args gets reallocated since it was used already by the *arg unpacking. Signed-off-by: David Lechner <david@pybricks.com>
37 lines
711 B
Python
37 lines
711 B
Python
# test calling a function with *tuple and **dict
|
|
|
|
def f(a, b, c, d):
|
|
print(a, b, c, d)
|
|
|
|
f(*(1, 2), **{'c':3, 'd':4})
|
|
f(*(1, 2), **{['c', 'd'][i]:(3 + i) for i in range(2)})
|
|
|
|
try:
|
|
eval("f(**{'a': 1}, *(2, 3, 4))")
|
|
except SyntaxError:
|
|
print("SyntaxError")
|
|
|
|
# test calling a method with *tuple and **dict
|
|
|
|
class A:
|
|
def f(self, a, b, c, d):
|
|
print(a, b, c, d)
|
|
|
|
a = A()
|
|
a.f(*(1, 2), **{'c':3, 'd':4})
|
|
a.f(*(1, 2), **{['c', 'd'][i]:(3 + i) for i in range(2)})
|
|
|
|
try:
|
|
eval("a.f(**{'a': 1}, *(2, 3, 4))")
|
|
except SyntaxError:
|
|
print("SyntaxError")
|
|
|
|
|
|
# coverage test for arg allocation corner case
|
|
|
|
def f2(*args, **kwargs):
|
|
print(len(args), len(kwargs))
|
|
|
|
|
|
f2(*iter(range(4)), **{'a': 1})
|