Debian Codegraph @

test/static_analysis/star_arguments.py

raw symbols SCIP
1 # -----------------
2 # *args
3 # -----------------
4
5
6 def simple(a):
7 return a
8
9
10 def nested(*args):
11 return simple(*args)
12
13 nested(1)
14 #! 6 type-error-too-few-arguments
15 nested()
16
17
18 def nested_no_call_to_function(*args):
19 return simple(1, *args)
20
21
22 def simple2(a, b, c):
23 return b
24 def nested(*args):
25 return simple2(1, *args)
26 def nested_twice(*args1):
27 return nested(*args1)
28
29 nested_twice(2, 3)
30 #! 13 type-error-too-few-arguments
31 nested_twice(2)
32 #! 19 type-error-too-many-arguments
33 nested_twice(2, 3, 4)
34
35
36 # A named argument can be located before *args.
37 def star_args_with_named(*args):
38 return simple2(c='', *args)
39
40 star_args_with_named(1, 2)
41 # -----------------
42 # **kwargs
43 # -----------------
44
45
46 def kwargs_test(**kwargs):
47 return simple2(1, **kwargs)
48
49 kwargs_test(c=3, b=2)
50 #! 12 type-error-too-few-arguments
51 kwargs_test(c=3)
52 #! 12 type-error-too-few-arguments
53 kwargs_test(b=2)
54 #! 22 type-error-keyword-argument
55 kwargs_test(b=2, c=3, d=4)
56 #! 12 type-error-multiple-values
57 kwargs_test(b=2, c=3, a=4)
58
59
60 def kwargs_nested(**kwargs):
61 return kwargs_test(b=2, **kwargs)
62
63 kwargs_nested(c=3)
64 #! 13 type-error-too-few-arguments
65 kwargs_nested()
66 #! 19 type-error-keyword-argument
67 kwargs_nested(c=2, d=4)
68 #! 14 type-error-multiple-values
69 kwargs_nested(c=2, a=4)
70 # TODO reenable
71 ##! 14 type-error-multiple-values
72 #kwargs_nested(b=3, c=2)
73
74 # -----------------
75 # mixed *args/**kwargs
76 # -----------------
77
78 def simple_mixed(a, b, c):
79 return b
80
81 def mixed(*args, **kwargs):
82 return simple_mixed(1, *args, **kwargs)
83
84 mixed(1, 2)
85 mixed(1, c=2)
86 mixed(b=2, c=3)
87 mixed(c=4, b='')
88
89 # need separate functions, otherwise these might swallow the errors
90 def mixed2(*args, **kwargs):
91 return simple_mixed(1, *args, **kwargs)
92
93
94 #! 7 type-error-too-few-arguments
95 mixed2(c=2)
96 #! 7 type-error-too-few-arguments
97 mixed2(3)
98 #! 13 type-error-too-many-arguments
99 mixed2(3, 4, 5)
100 # TODO reenable
101 ##! 13 type-error-too-many-arguments
102 #mixed2(3, 4, c=5)
103 #! 7 type-error-multiple-values
104 mixed2(3, b=5)
105
106 # -----------------
107 # plain wrong arguments
108 # -----------------
109
110 #! 12 type-error-star-star
111 simple(1, **[])
112 #! 12 type-error-star-star
113 simple(1, **1)
114 class A(): pass
115 #! 12 type-error-star-star
116 simple(1, **A())
117
118 #! 11 type-error-star
119 simple(1, *1)