Repository navigation
fix(model): let type checkers see the db helpers instead of their stand-ins - #7406
FarhanAliRaza merged 4 commits into
Conversation
|
Merging this PR will improve performance by 5.61%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | test_hydration_metadata[20] |
220.5 µs | 208.8 µs | +5.61% |
Tip
Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing benedikt-bartscher:model-db-symbols-type-checking (d0f4130) with main (deea1c3)
Footnotes
-
18 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
reflex.modeldefines its database helpers only when the db extra is installed (if find_spec("sqlalchemy"):and two more blocks like it), and binds stand-ins that point at the extra otherwise. pyright takes the definitions from theifbranch (theelseassignments carry# pyright: ignore), but ty unions both branches, so every helper came out unioned with its stand-in:The three conditions are now
TYPE_CHECKING or ..., so checkers see the real definitions, as if the extra were installed. At runtimeTYPE_CHECKINGis false and the conditions are unchanged.tests/type_checking/model.pyasserts the types ofModelRegistry.get_metadata(),get_engine(),sqla_session(),migrate(),rx.session()andrx.asession(); under ty it fails with 6 errors before this change. The model unit tests and pyright over all files pass.