Repository navigation
Commit ceb01c1
authored
Narrow none_member in JSON schema union handling (#1121)
Follow-up to #1028.
#1028 introduced `none_member: mi.Type | None` in the union branch of
`_json_schema.py` and guarded the `self.to_schema(none_member)` calls
with a separate `has_none` boolean. mypy can't narrow `none_member`
through the flag, so it errors:
```
_json_schema.py:363: error: Argument 1 to "to_schema" of "_SchemaGenerator" has incompatible type "Type | None"; expected "Type" [arg-type]
```
This is not caught by current CI because the msgspec source is not
type-checked there (only `tests/typing` is); #1116 (adding stubtest) is
what surfaces it. Fixing it here so #1116 can go green.
The fix drops the redundant `has_none` flag and checks `none_member is
not None` at the call sites, which gives mypy the narrowing. No runtime
behavior change (`has_none` and `none_member` were always set together):
`tests/unit/test_schema.py` still passes (115), and stubtest with mypy
2.2.0 is clean.
Co-authored-by: Siyet <[email protected]>1 parent e1c6f23 commit ceb01c1
1 file changed
Lines changed: 4 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
333 | | - | |
334 | 333 | | |
335 | 334 | | |
336 | 335 | | |
| |||
341 | 340 | | |
342 | 341 | | |
343 | 342 | | |
344 | | - | |
345 | 343 | | |
346 | 344 | | |
347 | 345 | | |
| |||
359 | 357 | | |
360 | 358 | | |
361 | 359 | | |
362 | | - | |
| 360 | + | |
363 | 361 | | |
364 | 362 | | |
365 | | - | |
| 363 | + | |
366 | 364 | | |
367 | 365 | | |
368 | 366 | | |
369 | 367 | | |
370 | 368 | | |
371 | 369 | | |
372 | | - | |
| 370 | + | |
373 | 371 | | |
374 | 372 | | |
375 | 373 | | |
376 | | - | |
| 374 | + | |
377 | 375 | | |
378 | 376 | | |
379 | 377 | | |
| |||
0 commit comments