Skip to content

fix issubclass calls#5753

Merged
adhami3310 merged 2 commits into
mainfrom
fix-issubclass-calls
Sep 2, 2025
Merged

fix issubclass calls#5753
adhami3310 merged 2 commits into
mainfrom
fix-issubclass-calls

Conversation

@adhami3310

Copy link
Copy Markdown
Member

this should fix regressions as in: #5747 (comment)_

there's performance implications in the change in components.py, will be looking at those as well

@greptile-apps greptile-apps 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.

Greptile Summary

This PR fixes regressions related to issubclass calls that were causing TypeError exceptions when working with certain type annotations. The changes address two specific areas where unsafe type checking was occurring:

Component Property Detection (reflex/components/component.py):
The PR removes an optimization in the Component class that attempted to cache component property names using issubclass(field_type, Component) checks. This optimization was causing issues when field types weren't fully resolved or were complex type annotations. The code now falls back to a simpler approach that directly iterates through all props and checks each value at runtime, eliminating the problematic type introspection.

Literal Type Handling (reflex/utils/types.py):
The PR adds proper handling for Python's Literal types in the is_valid_var_type function. Previously, when Literal types (like Literal['a', 'b']) were passed to issubclass(), it would raise a TypeError since Literal types are not actual classes. The fix extracts the actual types from the literal values (e.g., extracting str from string literals) and validates those recursively.

These changes integrate well with the existing codebase by following established patterns - the Literal handling mirrors the existing Union type handling approach, and the component property detection falls back to the reliable runtime checking that was already in place as a fallback mechanism.

Confidence score: 4/5

  • This PR is safe to merge with minimal risk of introducing new issues
  • Score reflects targeted fixes for well-documented regressions with clear error patterns
  • Pay attention to performance implications in component property detection as noted by the developer

2 files reviewed, 2 comments

Edit Code Review Bot Settings | Greptile

Comment thread reflex/utils/types.py
Comment thread reflex/utils/types.py
@codspeed-hq

codspeed-hq Bot commented Sep 2, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #5753 will not alter performance

Comparing fix-issubclass-calls (08885dc) with main (b28f873)

Summary

✅ 8 untouched benchmarks

@adhami3310 adhami3310 merged commit 5a87e31 into main Sep 2, 2025
41 checks passed
@adhami3310 adhami3310 deleted the fix-issubclass-calls branch September 2, 2025 19:04
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.

2 participants