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

Use TypeVar for Schema.schema type #520

Closed
wants to merge 1 commit into from

Conversation

cdce8p
Copy link
Contributor

@cdce8p cdce8p commented Jun 26, 2024

Schemable is great as a catch all case. However, the Union prevents further uses especially of the schema attribute.
E.g.

schema = vol.Schema({"key": str})
schema.schema.items()  # should access the dict items used to create the schema

This PR changes the schema attribute type to a TypeVar. This allows for either implicit or explicit specialization by the user. It would fallback to typing.Any if type checkers can't infer the specialized type.

That's still better than the current situation as that just always emits an error.

error: Item "type" of "Schema | Object | Mapping[Any, Any] | list[Any] | tuple[Any, ...] |
    <12 more items> | None" has no attribute "__iter__" (not iterable)  [union-attr]

Refs home-assistant/core#120268

@cdce8p cdce8p marked this pull request as draft June 26, 2024 00:20
@cdce8p
Copy link
Contributor Author

cdce8p commented Jun 26, 2024

Closed in favor of #521

@cdce8p cdce8p closed this Jun 26, 2024
@cdce8p cdce8p deleted the schema-attr-type branch June 26, 2024 20:29
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