Skip to content

fix(pyi): mark union props optional in generated stubs - #7080

Open
benedikt-bartscher wants to merge 2 commits into
reflex-dev:mainfrom
benedikt-bartscher:fix-pyi-union-prop-optional
Open

fix(pyi): mark union props optional in generated stubs#7080
benedikt-bartscher wants to merge 2 commits into
reflex-dev:mainfrom
benedikt-bartscher:fix-pyi-union-prop-optional

Conversation

@benedikt-bartscher

@benedikt-bartscher benedikt-bartscher commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

_get_type_hint returned early for a union annotation and dropped the | None the caller asked for, so a prop declared as a union got a stub signature whose default contradicts its type:

content: Component | Var[str] | str = None

A non-union prop already went through the is_optional branch at the end of the function and came out as Var[bool] | bool | None, so this only ever hit props annotated as an explicit union — HighLevelTooltip.content, HighLevelAccordion.items and Badge.color_scheme today. Type checkers flag the generated signature itself; running pyright over the packages reports five reportArgumentType errors that no source change can fix.

Honour is_optional in both union branches (typed and string annotations). Only markdown.pyi changes among the tracked stubs.

Review in cubic

`_get_type_hint` returned early for a union annotation and dropped the
`| None` the caller asked for, so a prop declared as a union got a stub
signature whose default contradicts its type:

    content: Component | Var[str] | str = None

A non-union prop already went through the `is_optional` branch at the end
of the function and came out as `Var[bool] | bool | None`, so this only
ever hit props annotated as an explicit union — HighLevelTooltip.content,
HighLevelAccordion.items and Badge.color_scheme today. Type checkers flag
the generated signature itself; running pyright over the packages reports
five reportArgumentType errors that no source change can fix.

Honour `is_optional` in both union branches (typed and string
annotations). Only markdown.pyi changes among the tracked stubs.
@benedikt-bartscher
benedikt-bartscher force-pushed the fix-pyi-union-prop-optional branch from b6c5cce to 8f0fbf6 Compare September 10, 2026 20:53
@greptile-apps

greptile-apps Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge with no actionable correctness, security, or repository-rule issues identified.

Summary

  • Updates both runtime and string-annotation union handling.
  • Adds focused regression tests for optional union rendering.
  • Adds a representative component fixture and updates its golden stub.
  • Refreshes the generated-stub hash and package news fragments.

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

@codspeed-hq

codspeed-hq Bot commented Sep 10, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 40 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing benedikt-bartscher:fix-pyi-union-prop-optional (0b3af79) with main (9165dc6)

Open in CodSpeed

Footnotes

  1. 8 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 September 12, 2026 18:29
@benedikt-bartscher
benedikt-bartscher requested a review from a team as a code owner September 12, 2026 18:29

@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 7 files

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant