summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/fun_callstardblstar.py
blob: c08e46f668eb77d287439b9ef76f9859a662a3f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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})

# 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)})

# 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=",")