refactor(reflex-base): consolidate BaseContext into context.base (#6514)#6553
refactor(reflex-base): consolidate BaseContext into context.base (#6514)#6553BABTUNA wants to merge 2 commits into
Conversation
…lex-dev#6514) Removes the duplicate BaseContext defined in plugins/compiler.py and makes PageContext/CompileContext inherit from reflex_base.context.base. Converts BaseContext from a frozen dataclass to a plain class with __slots__ = () so frozen (RegistrationContext, EventContext) and non-frozen (PageContext, CompileContext) subclasses can both inherit. Ports the async __aenter__/__aexit__ helpers over from the removed copy, and pins identity equality on the base via object.__eq__ / object.__hash__. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Greptile SummaryThis PR consolidates the duplicate
Confidence Score: 4/5Safe to merge; the consolidation is straightforward and the test suite covers the important paths. The refactor is clean and well-tested. The one substantive concern is that
Important Files Changed
|
The remaining "must be entered with 'with' or 'async with'" regex in test_compile_context_requires_attached_context didn't match the consolidated BaseContext's "must be entered before calling this method" message, so all 10 unit-tests jobs failed on CI. Loosen the regex to match the prefix shared by the new wording.
Summary
BaseContextdefined inreflex_base.plugins.compilerand pointsPageContext/CompileContextat the canonicalreflex_base.context.base.BaseContext.BaseContextfrom a frozen dataclass into a plain class with__slots__ = ()so frozen subclasses (RegistrationContext,EventContext) and non-frozen subclasses (PageContext,CompileContext) can both inherit. Ports the async__aenter__/__aexit__helpers over from the removed copy.__eq__ = object.__eq__/__hash__ = object.__hash__, and propagateseq=Falseto the (formerly compiler-local) dataclass subclasses.Closes #6514.
Test plan
uv run pytest tests/units/reflex_base/context/test_base.py tests/units/compiler/test_plugins.pyuv run pytest tests/units(full unit suite)uv run ruff check . && uv run ruff format --check .uv run pyright reflex tests