Commit c2138d8
authored
Use .get() for discriminator access in generated union encoders (#176)
Why
===
Follow-up to #175. The discriminator field in a discriminated union may
be `NotRequired` in the TypedDict. Direct key access (`x["shapeType"]`)
triggers pyright's `reportTypedDictNotRequiredAccess` error.
This broke the pid2 codegen CI when the scribe schema added
discriminated union variants where the discriminator field is optional.
What changed
============
Use `x.get("key")` instead of `x["key"]` for discriminator checks in the
generated ternary chain. This is safe because a missing key returns
`None`, which won't match any discriminator value and falls through to
the next branch.
Test plan
=========
- All 64 tests pass
- Updated snapshot for `test_unknown_enum`
- Tested end-to-end against the pid2 schema from ai-infra — codegen,
mypy, and pyright all pass
~ written by Zerg 👾1 parent 35ea72f commit c2138d8
File tree
2 files changed
+2
-2
lines changed- src/replit_river/codegen
- tests/v1/codegen/snapshot/snapshots/test_unknown_enum/enumService
2 files changed
+2
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
342 | 342 | | |
343 | 343 | | |
344 | 344 | | |
345 | | - | |
| 345 | + | |
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
| 78 | + | |
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| |||
0 commit comments