2014-03-30 16:21:24 -04:00
|
|
|
# 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)})
|
|
|
|
|
2020-03-25 00:54:45 -04:00
|
|
|
try:
|
|
|
|
eval("f(**{'a': 1}, *(2, 3, 4))")
|
|
|
|
except SyntaxError:
|
|
|
|
print("SyntaxError")
|
|
|
|
|
2014-03-30 16:21:24 -04:00
|
|
|
# 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)})
|
2020-03-25 00:54:45 -04:00
|
|
|
|
|
|
|
try:
|
|
|
|
eval("a.f(**{'a': 1}, *(2, 3, 4))")
|
|
|
|
except SyntaxError:
|
|
|
|
print("SyntaxError")
|
2022-03-29 14:15:15 -04:00
|
|
|
|
|
|
|
|
|
|
|
# coverage test for arg allocation corner case
|
|
|
|
|
|
|
|
def f2(*args, **kwargs):
|
|
|
|
print(len(args), len(kwargs))
|
|
|
|
|
|
|
|
|
|
|
|
f2(*iter(range(4)), **{'a': 1})
|
2022-03-31 09:21:58 -04:00
|
|
|
|
|
|
|
# case where *args is not a tuple/list and takes up most of the memory allocated for **kwargs
|
|
|
|
f2(*iter(range(100)), **{str(i): i for i in range(100)})
|
2022-08-05 19:52:13 -04:00
|
|
|
|
|
|
|
# regression test - iterable with unknown len() was exactly using preallocated
|
|
|
|
# memory causing args 4 and 5 to overflow the allocated arg array
|
|
|
|
print(1, *iter((1, 2, 3)), *iter((1, 2, 3)), 4, 5, sep=",")
|