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

feat(types): adds support for TypeGuard and TypeIs #5194

Merged
merged 4 commits into from
Jun 26, 2024

Conversation

InvincibleRMC
Copy link
Contributor

Description

Allows annotating functions for type narrowing using TypeGuard or TypeIs.

For additional information relating to the specific differences between TypeGuard and TypeIs can be found here.

def is_str_type_guard(x: object) -> TypeGuard[str]:
    return isinstance(x, str)

def is_str_type_is(x: object) -> TypeIs[str]:
    return isinstance(x, str)

Suggested changelog entry:

   Adds support for `typing.TypeGuard` and `typing.TypeIs`.

@henryiii henryiii changed the title Adds support for TypeGuard and TypeIs feat(types): adds support for TypeGuard and TypeIs Jun 25, 2024
@henryiii henryiii merged commit 2be85c6 into pybind:master Jun 26, 2024
84 checks passed
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Jun 26, 2024
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Jun 26, 2024
@InvincibleRMC InvincibleRMC deleted the typing-type-is-type-guard branch June 26, 2024 12:56
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