Skip to content

fix(vars): type LiteralObjectVar.create to take any value that serializes to a mapping - #7403

Merged
masenf merged 3 commits into
reflex-dev:mainfrom
benedikt-bartscher:literal-object-var-create-any-value
Oct 9, 2026
Merged

masenf merged 3 commits into
reflex-dev:mainfrom
benedikt-bartscher:literal-object-var-create-any-value

Conversation

@benedikt-bartscher

@benedikt-bartscher benedikt-bartscher commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

LiteralObjectVar.create annotated its value as Mapping, but takes anything that serializes to a mapping: a value that is not a mapping goes through serialize, and only a result that is not a mapping raises TypeError (its docstring says "a mapping type or a dataclass"). So pyright and ty rejected calls that work:

@dataclasses.dataclass
class Point:
    x: int

LiteralObjectVar.create(Point(1))  # Argument of type "Point" cannot be assigned to parameter "_var_value" of type "Mapping[Unknown, Unknown]"

The value is now annotated object, which is what the method checks at runtime, and the docstring names what it takes. Runtime behaviour is unchanged.

tests/type_checking/vars.py makes that call; it fails under pyright and ty before this change. The full unit suite and pyright pass.

Review in cubic

@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

This PR changes LiteralObjectVar.create’s parameter annotation to accept values that serialize to mappings, matching its existing runtime behavior.

  • Adds a dataclass call to the type-checking tests and a news fragment.
  • The update since the previous review aligns the test’s assert_type import with the current Python 3.11 minimum.

Reviews (2) · Last reviewed commit: "Merge remote-tracking branch 'upstream/m..." · Reviewed by Greptile

@codspeed

codspeed Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 12.95%

⚡ 2 improved benchmarks
✅ 148 untouched benchmarks
⏩ 18 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_hydration_metadata[200] 2 ms 1.7 ms +20.76%
⚡ test_hydration_metadata[20] 218.9 µs 207.2 µs +5.64%

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:literal-object-var-create-any-value (1b2143a) with main (beef0ae)

Open in CodSpeed

Footnotes

  1. 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. ↩

@benedikt-bartscher
benedikt-bartscher marked this pull request as ready for review October 3, 2026 13:40
@benedikt-bartscher
benedikt-bartscher requested a review from a team as a code owner October 3, 2026 13:40

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

@masenf masenf added the on deck PRs lined up to review / merge next label Oct 5, 2026
FarhanAliRaza
FarhanAliRaza previously approved these changes Oct 5, 2026
@masenf
masenf merged commit fa086a8 into reflex-dev:main Oct 9, 2026
146 checks passed
@benedikt-bartscher
benedikt-bartscher deleted the literal-object-var-create-any-value branch October 11, 2026 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

on deck PRs lined up to review / merge next

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants