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): add type[T] support to typing.h #5166

Merged
merged 4 commits into from
Jun 15, 2024

Conversation

InvincibleRMC
Copy link
Contributor

@InvincibleRMC InvincibleRMC commented Jun 14, 2024

Description

Similar to #5165 but, adds support for type[] (see https://docs.python.org/3.10/library/typing.html#typing.Type).

The benefit of adding support for type[] allows type checkers to differentiate between different types.

By default foo could take any valid python type E.g. float or str

def foo(a: type) -> None: ...

But with allowing specific the type it can narrow valid input properly and str would no long be valid.

def foo(a: type[int]) -> None: ...

Suggested changelog entry:

Support for ``type[T]`` was added to pybind11/typing.h.

@rwgk
Copy link
Collaborator

rwgk commented Jun 14, 2024

I'm not a typing expert. For people like myself, could you please explain in the PR description why adding type[] is useful?

@rwgk
Copy link
Collaborator

rwgk commented Jun 15, 2024

Hi @InvincibleRMC, could you help by resolving the merge conflicts (I just merged your #5165)?

@rwgk rwgk merged commit 7c4ac91 into pybind:master Jun 15, 2024
83 checks passed
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Jun 15, 2024
@henryiii henryiii changed the title Add type[T] support to typing.h feat(typing): add type[T] support to typing.h Jun 23, 2024
@henryiii henryiii changed the title feat(typing): add type[T] support to typing.h feat(types): add type[T] support to typing.h Jun 23, 2024
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Jun 26, 2024
@InvincibleRMC InvincibleRMC deleted the typing-type branch July 1, 2024 13:47
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