Commit ca9d552
authored
feat/finishing typeddict inputs (#95)
Why
===
We got pretty close to having TypedDicts for river-python inputs before,
but had to roll back due to a protocol mismatch.
Trying again, and also adding some tests to confirm that at the very
least the Pydantic models can decode was was encoded by the TypedDict
encoders. It's not a perfect science, but it should be good enough to
start building more confidence as we make additional progress.
### The reason for "janky" tests
There's a bit of a chicken-and-egg situation when trying to test code
generation at runtime.
We have three options:
- write pytest handlers where each invocation runs the codegen with a
temp target (like the shell script does here), writes a static file for
each text into that directory, then executes a new python into that
directory. The challenge with this is that it would suck to write or
maintain.
- write pytest handlers which runs the codegen with unique module name
targets (like `gen1`, `gen2`, `gen3`, one for each codegen run
necessary) and carefully juggle the imports to make sure we don't try to
import something that's not there yet. This _might_ be the best option,
but I'm not convinced about the ergonomics at the moment. It might be OK
though, with highly targeted `.gitignore`'s.
- maintain a bespoke test runner, optimize for writing and maintaining
these tests, and just acknowledge that we are doing something obscure
and difficult.
I definitely wrote the tests here in a way that would give some coverage
and also provide confidence, while intentionally deferring the above
decision so we can keep making progress. in the meantime.
What changed
============
- Added some janky tests for comparing the encoding of both models
- Fixed many bugs in the TypedDict codegen and encoders
Test plan
=========
```
$ bash scripts/parity.sh
Using /tmp/river-codegen-parity.bAZ
Starting...
Verified
```1 parent 62b236e commit ca9d552
5 files changed
Lines changed: 326 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
83 | 93 | | |
84 | | - | |
| 94 | + | |
85 | 95 | | |
86 | 96 | | |
87 | 97 | | |
| |||
219 | 229 | | |
220 | 230 | | |
221 | 231 | | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | 232 | | |
231 | 233 | | |
232 | 234 | | |
| |||
273 | 275 | | |
274 | 276 | | |
275 | 277 | | |
276 | | - | |
| 278 | + | |
277 | 279 | | |
278 | 280 | | |
279 | 281 | | |
280 | 282 | | |
281 | 283 | | |
282 | 284 | | |
283 | | - | |
| 285 | + | |
284 | 286 | | |
285 | 287 | | |
286 | | - | |
| 288 | + | |
287 | 289 | | |
288 | 290 | | |
289 | 291 | | |
290 | 292 | | |
291 | 293 | | |
292 | 294 | | |
293 | | - | |
| 295 | + | |
294 | 296 | | |
295 | 297 | | |
296 | 298 | | |
297 | 299 | | |
298 | 300 | | |
299 | 301 | | |
300 | | - | |
| 302 | + | |
301 | 303 | | |
302 | 304 | | |
303 | | - | |
| 305 | + | |
304 | 306 | | |
305 | 307 | | |
306 | | - | |
| 308 | + | |
307 | 309 | | |
308 | 310 | | |
309 | | - | |
| 311 | + | |
310 | 312 | | |
311 | 313 | | |
312 | 314 | | |
313 | | - | |
| 315 | + | |
314 | 316 | | |
315 | 317 | | |
316 | 318 | | |
| |||
323 | 325 | | |
324 | 326 | | |
325 | 327 | | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
326 | 331 | | |
| 332 | + | |
327 | 333 | | |
328 | 334 | | |
329 | 335 | | |
| |||
353 | 359 | | |
354 | 360 | | |
355 | 361 | | |
356 | | - | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
357 | 369 | | |
358 | 370 | | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
366 | 386 | | |
367 | | - | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
368 | 391 | | |
369 | 392 | | |
370 | 393 | | |
| |||
403 | 426 | | |
404 | 427 | | |
405 | 428 | | |
| 429 | + | |
406 | 430 | | |
407 | | - | |
| 431 | + | |
408 | 432 | | |
409 | 433 | | |
410 | 434 | | |
| |||
449 | 473 | | |
450 | 474 | | |
451 | 475 | | |
452 | | - | |
| 476 | + | |
453 | 477 | | |
454 | 478 | | |
455 | 479 | | |
| |||
482 | 506 | | |
483 | 507 | | |
484 | 508 | | |
485 | | - | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
486 | 512 | | |
487 | 513 | | |
488 | 514 | | |
| |||
517 | 543 | | |
518 | 544 | | |
519 | 545 | | |
520 | | - | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
521 | 560 | | |
522 | 561 | | |
523 | 562 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
0 commit comments