Repository navigation
Commit 15c29eb
Tighten _to_serializable docs and drop casts that were not load-bearing
The docstring promised a "JSON-safe structure", which the function does
not guarantee: values reached through dict[str, Any] fields keep their
original behavior, and a few shapes -- a tuple holding a datetime, for
one -- were never JSON-encodable. Say that plainly rather than implying
every output can be encoded.
The list and dict branches test value_type rather than the value, so the
value is never narrowed and iterating it directly is already clean under
strict type checking. The casts there did nothing but call typing.cast
on every container.
The cast on the type lookup is load-bearing and now says so. type(value)
is type[Unknown] to a checker because value is Any. Two details that
look like noise are deliberate: the quoted annotation avoids building a
throwaway GenericAlias per call, and the lookup stays type(value) rather
than the cheaper value.__class__ because asdict dispatched on type(obj).
Dispatching on __class__ would let an object claiming to be a str take
the JSON-native fast path and be returned by reference, where the
original pipeline deep-copied it. A regression test pins that, and fails
if the swap is made.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6322dc7f-81ee-4d42-be2d-cef84cf62d151 parent e31bb48 commit 15c29eb
2 files changed
Lines changed: 66 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
389 | 389 | | |
390 | 390 | | |
391 | 391 | | |
392 | | - | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
393 | 399 | | |
394 | 400 | | |
395 | 401 | | |
| |||
404 | 410 | | |
405 | 411 | | |
406 | 412 | | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
407 | 421 | | |
408 | 422 | | |
409 | 423 | | |
| |||
417 | 431 | | |
418 | 432 | | |
419 | 433 | | |
420 | | - | |
| 434 | + | |
421 | 435 | | |
422 | 436 | | |
423 | 437 | | |
424 | 438 | | |
425 | 439 | | |
426 | 440 | | |
427 | 441 | | |
428 | | - | |
| 442 | + | |
429 | 443 | | |
430 | 444 | | |
431 | 445 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
582 | 582 | | |
583 | 583 | | |
584 | 584 | | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
585 | 613 | | |
586 | 614 | | |
587 | 615 | | |
| |||
608 | 636 | | |
609 | 637 | | |
610 | 638 | | |
| 639 | + | |
611 | 640 | | |
612 | 641 | | |
613 | 642 | | |
| |||
770 | 799 | | |
771 | 800 | | |
772 | 801 | | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
773 | 822 | | |
774 | 823 | | |
775 | 824 | | |
| |||
0 commit comments