feat: Add UnionType support to query method #5578
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Union Type Support to Query Method
This PR adds support for using Python's Union type syntax (
|
) in the query method, allowing developers to search for multiple widget types in a single query. This makes the API more intuitive and concise when searching for different kinds of widgets.Features
|
operator(Input | Select) | Static
)Usage Examples
Technical Details
The implementation converts Union types into CSS selectors internally, maintaining compatibility with the existing query system. It handles nested unions by recursively extracting all unique widget types and validates that all types in the union are Widget subclasses.
Testing
Added comprehensive test coverage including:
Backwards Compatibility
This change is fully backwards compatible. Existing query usage with strings, single types, or None continues to work as before.
Please review the following checklist.