Debian Codegraph @

tests/data/cases/conditional_expression.py

raw
1 long_kwargs_single_line = my_function(
2 foo="test, this is a sample value",
3 bar=some_long_value_name_foo_bar_baz if some_boolean_variable else some_fallback_value_foo_bar_baz,
4 baz="hello, this is a another value",
5 )
6
7 multiline_kwargs_indented = my_function(
8 foo="test, this is a sample value",
9 bar=some_long_value_name_foo_bar_baz
10 if some_boolean_variable
11 else some_fallback_value_foo_bar_baz,
12 baz="hello, this is a another value",
13 )
14
15 imploding_kwargs = my_function(
16 foo="test, this is a sample value",
17 bar=a
18 if foo
19 else b,
20 baz="hello, this is a another value",
21 )
22
23 imploding_line = (
24 1
25 if 1 + 1 == 2
26 else 0
27 )
28
29 exploding_line = "hello this is a slightly long string" if some_long_value_name_foo_bar_baz else "this one is a little shorter"
30
31 positional_argument_test(some_long_value_name_foo_bar_baz if some_boolean_variable else some_fallback_value_foo_bar_baz)
32
33 def weird_default_argument(x=some_long_value_name_foo_bar_baz
34 if SOME_CONSTANT
35 else some_fallback_value_foo_bar_baz):
36 pass
37
38 nested = "hello this is a slightly long string" if (some_long_value_name_foo_bar_baz if
39 nesting_test_expressions else some_fallback_value_foo_bar_baz) \
40 else "this one is a little shorter"
41
42 generator_expression = (
43 some_long_value_name_foo_bar_baz if some_boolean_variable else some_fallback_value_foo_bar_baz for some_boolean_variable in some_iterable
44 )
45
46
47 def limit_offset_sql(self, low_mark, high_mark):
48 """Return LIMIT/OFFSET SQL clause."""
49 limit, offset = self._get_limit_offset_params(low_mark, high_mark)
50 return " ".join(
51 sql
52 for sql in (
53 "LIMIT %d" % limit if limit else None,
54 ("OFFSET %d" % offset) if offset else None,
55 )
56 if sql
57 )
58
59
60 def something():
61 clone._iterable_class = (
62 NamedValuesListIterable
63 if named
64 else FlatValuesListIterable
65 if flat
66 else ValuesListIterable
67 )
68
69
70 def foo(wait: bool = True):
71 # This comment is two
72 # lines long
73
74 # This is only one
75 time.sleep(1) if wait else None
76 time.sleep(1) if wait else None
77
78 # With newline above
79 time.sleep(1) if wait else None
80 # Without newline above
81 time.sleep(1) if wait else None
82
83
84 a = "".join(
85 (
86 "", # comment
87 "" if True else "",
88 )
89 )
90
91 # output
92
93 long_kwargs_single_line = my_function(
94 foo="test, this is a sample value",
95 bar=(
96 some_long_value_name_foo_bar_baz
97 if some_boolean_variable
98 else some_fallback_value_foo_bar_baz
99 ),
100 baz="hello, this is a another value",
101 )
102
103 multiline_kwargs_indented = my_function(
104 foo="test, this is a sample value",
105 bar=(
106 some_long_value_name_foo_bar_baz
107 if some_boolean_variable
108 else some_fallback_value_foo_bar_baz
109 ),
110 baz="hello, this is a another value",
111 )
112
113 imploding_kwargs = my_function(
114 foo="test, this is a sample value",
115 bar=a if foo else b,
116 baz="hello, this is a another value",
117 )
118
119 imploding_line = 1 if 1 + 1 == 2 else 0
120
121 exploding_line = (
122 "hello this is a slightly long string"
123 if some_long_value_name_foo_bar_baz
124 else "this one is a little shorter"
125 )
126
127 positional_argument_test(
128 some_long_value_name_foo_bar_baz
129 if some_boolean_variable
130 else some_fallback_value_foo_bar_baz
131 )
132
133
134 def weird_default_argument(
135 x=(
136 some_long_value_name_foo_bar_baz
137 if SOME_CONSTANT
138 else some_fallback_value_foo_bar_baz
139 ),
140 ):
141 pass
142
143
144 nested = (
145 "hello this is a slightly long string"
146 if (
147 some_long_value_name_foo_bar_baz
148 if nesting_test_expressions
149 else some_fallback_value_foo_bar_baz
150 )
151 else "this one is a little shorter"
152 )
153
154 generator_expression = (
155 (
156 some_long_value_name_foo_bar_baz
157 if some_boolean_variable
158 else some_fallback_value_foo_bar_baz
159 )
160 for some_boolean_variable in some_iterable
161 )
162
163
164 def limit_offset_sql(self, low_mark, high_mark):
165 """Return LIMIT/OFFSET SQL clause."""
166 limit, offset = self._get_limit_offset_params(low_mark, high_mark)
167 return " ".join(
168 sql
169 for sql in (
170 "LIMIT %d" % limit if limit else None,
171 ("OFFSET %d" % offset) if offset else None,
172 )
173 if sql
174 )
175
176
177 def something():
178 clone._iterable_class = (
179 NamedValuesListIterable
180 if named
181 else FlatValuesListIterable if flat else ValuesListIterable
182 )
183
184
185 def foo(wait: bool = True):
186 # This comment is two
187 # lines long
188
189 # This is only one
190 time.sleep(1) if wait else None
191 time.sleep(1) if wait else None
192
193 # With newline above
194 time.sleep(1) if wait else None
195 # Without newline above
196 time.sleep(1) if wait else None
197
198
199 a = "".join(
200 (
201 "", # comment
202 "" if True else "",
203 )
204 )