DO NOT MERGE - Codspeed run only - Rel fix pep695 alias runtime perf isinstance - #6988
Conversation
PR reflex-dev#6944 added resolve_type_alias() but wired it only into Var.guess_type, so alias-annotated state vars compiled while every runtime path that re-checks the raw annotation still choked on the TypeAliasType: - State.__setattr__ validates assignments through _isinstance(), which fell through to the bare isinstance() call and raised "TypeError: isinstance() arg 2 must be a type" on every assignment to an alias-annotated var, aborting the event handler instead of at most logging a mismatch (0.9.9a1 pre-release FINDING-002). - Passing an event handler with an alias-annotated argument uncalled to an event trigger crashed page compile: typehint_issubclass() reached the bare issubclass() for a plain alias and failed the origin comparison for a subscripted one, escalating to a fatal error (FINDING-006). Resolve the alias at the entry of both functions, reusing resolve_type_alias(), which already handles parameterized aliases (Items[str]) and aliases nested in unions (Key | None). Alias-annotated vars now behave exactly like their resolved annotations at runtime. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EMjBXPozsNeQNSBZecNH8x
…ntime' into rel-fix-pep695-alias-runtime-perf-isinstance
Merging this PR will not alter performance
Performance Changes
Comparing Footnotes
|
|
seems like a better version of #6986 |
Greptile SummaryThis PR adds runtime support for PEP 695 aliases in type validation while reducing repeated work on validation and serialization hot paths.
Confidence Score: 5/5The PR appears safe to merge with no concrete blocking or independently actionable non-blocking issue identified. Alias resolution is applied before runtime type checks, the optimized origin checks preserve the prior helper semantics, and the deferred lookup caches retain the existing callable behavior.
|
| Filename | Overview |
|---|---|
| packages/reflex-base/src/reflex_base/utils/types.py | Adds alias resolution and memoized helper/import lookups without an identified correctness regression. |
| packages/reflex-base/src/reflex_base/utils/format.py | Caches the existing deferred serializer function while preserving caller-provided JSON defaults. |
| tests/units/reflex_base/utils/test_types.py | Covers bare, literal, generic, union-nested, native, and backported alias behavior. |
| tests/units/test_state.py | Verifies alias-annotated state assignments no longer crash or emit mismatch logs. |
| tests/benchmarks/test_isinstance.py | Adds representative scalar and nested-container benchmarks for the optimized validation paths. |
Reviews (1): Last reviewed commit: "Merge remote-tracking branch 'upstream/c..." | Re-trigger Greptile
this is #6986 and #6862 merged together - just for a codspeed run.