Commit 49d1804
committed
refactor: Put every openjd.expr crossing behind the one sys.modules guard
Addresses jericht's review on PR #341, which asked _is_expr_list to guard on
sys.modules before importing openjd.expr, the way _is_expr_null does.
Adding that guard literally would have been dead code: _is_expr_list had one
call site, reached only after _as_expr_value had already returned non-None
(which required the extension loaded) and after .is_null had been read off
the value. Instrumenting it confirmed this -- 4 real calls, all with an
ExprValue, all with the extension already loaded, none where the guard would
fire. Worse, its `return False` would mean "not a list", so if it ever did
fire the caller would stringify an EXPR list instead of flattening it into
separate argv entries: a silently wrong answer, not a safe fallback.
The concern underneath is real though. The asymmetry was hard to read, and a
future caller reaching _is_expr_list with an arbitrary value would have
loaded the extension through an unguarded import -- reintroducing the very
leak ce863b7 fixed.
So remove the asymmetry instead of documenting it. _as_expr_value and
_is_expr_list are replaced by a single _classify_expr_value returning an
_ExprKind (NOT_EXPR / NULL / LIST / SCALAR). It is now the only function in
the module that imports openjd.expr, and it sits behind the one guard, so
the property is structural rather than a docstring promise. _is_expr_null
becomes a one-line wrapper over it.
Behaviour is unchanged and the existing tests pass unmodified: 909 before,
909 after, same set.
Mutation-checked the new dispatch seam -- dropping or weakening the guard,
suppressing each of the four arms, misclassifying SCALAR as LIST or NULL,
and breaking either call-site arm are all caught by name. Two notes:
- Classifying SCALAR as LIST initially SURVIVED. A scalar ExprValue is not
iterable, so that misclassification raises TypeError out of the runner,
and no test passed a scalar whole-field EXPR argument through
resolve_action_arg_values -- list and null coverage left that arm open.
Adds test_let_bound_scalar_becomes_exactly_one_argument to close it.
- Inverting the NULL/LIST check order survives and should: a null value is
TypeCode.NULLTYPE and an empty list is not null, so the two conditions are
mutually exclusive and the order cannot matter. Verified rather than
assumed; recorded here as an equivalent mutant, not a gap.
Signed-off-by: David Leong <116610336+leongdl@users.noreply.github.com>1 parent 91c07f3 commit 49d1804
2 files changed
Lines changed: 88 additions & 43 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
148 | | - | |
149 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
150 | 174 | | |
151 | 175 | | |
152 | 176 | | |
153 | | - | |
154 | | - | |
155 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
156 | 180 | | |
157 | | - | |
| 181 | + | |
158 | 182 | | |
159 | 183 | | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | 184 | | |
166 | 185 | | |
167 | | - | |
168 | | - | |
| 186 | + | |
| 187 | + | |
169 | 188 | | |
170 | | - | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
171 | 196 | | |
172 | 197 | | |
173 | 198 | | |
174 | 199 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
| 200 | + | |
189 | 201 | | |
190 | 202 | | |
191 | 203 | | |
| |||
292 | 304 | | |
293 | 305 | | |
294 | 306 | | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
304 | 315 | | |
305 | | - | |
| 316 | + | |
306 | 317 | | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
311 | 322 | | |
312 | 323 | | |
313 | 324 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
286 | 320 | | |
287 | 321 | | |
288 | 322 | | |
| |||
0 commit comments