Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type schema attribute as Any #521

Merged
merged 1 commit into from
Jun 26, 2024
Merged

Conversation

cdce8p
Copy link
Contributor

@cdce8p cdce8p commented Jun 26, 2024

Schemable is great as parameter type. However, without a dedicated type annotation mypy will also use it as argument type for Schema.schema and Marker.schema which just creates unhelpful errors when used

error: Unsupported right operand type for in ("Schema | Object | Mapping[Any, Any] |
    list[Any] | tuple[Any, ...] | <12 more items> | None")  [operator]
error: Item "Schema" of "Schema | Object | Mapping[Any, Any] | list[Any] | tuple[Any, ...] |
    <12 more items> | None" has no attribute "items"  [union-attr]

Typing it as Any will "disable" type checking when using the schema attribute, while still providing the type safety for the parameter type.

An alternative would have been #520. However that comes with its own set of issues as now all Schemas are generic and need additional type annotations.

Refs home-assistant/core#120268

@alecthomas alecthomas merged commit 16163aa into alecthomas:master Jun 26, 2024
8 checks passed
@alecthomas
Copy link
Owner

Thanks!

@cdce8p cdce8p deleted the schema-type branch June 26, 2024 22:09
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.

3 participants