Skip to content

feat(types): add Union and Optional to typing.h - #5165

Merged
rwgk merged 14 commits into
pybind:masterfrom
InvincibleRMC:type-unions
Jun 15, 2024
Merged

feat(types): add Union and Optional to typing.h#5165
rwgk merged 14 commits into
pybind:masterfrom
InvincibleRMC:type-unions

Conversation

@InvincibleRMC

@InvincibleRMCInvincibleRMC commented Jun 13, 2024

Copy link
Copy Markdown
Contributor

Description

Add Union and Optional for better static typing on the python side.

Suggested changelog entry:

``Union`` and ``Optional`` were added to ``pybind11/typing.h``

@rwgk
rwgk marked this pull request as draft June 13, 2024 16:58
@rwgk

rwgk commented Jun 13, 2024

Copy link
Copy Markdown
Collaborator

Looks useful.

I just converted this to a Draft PR.

Could you please work on the GitHub Actions failures? Then click Ready for review and maybe tag me.

@InvincibleRMC

Copy link
Copy Markdown
ContributorAuthor

Will do. It seems to be falling into the default handle_type_name rather than the special case describe in typing.h but, will keep investigating.

@rwgk

rwgk commented Jun 13, 2024

Copy link
Copy Markdown
Collaborator

Maybe you just something like this?

https://github.com/pybind/pybind11/pull/5073/files

@InvincibleRMC

InvincibleRMC commented Jun 13, 2024

Copy link
Copy Markdown
ContributorAuthor

The solution was to inherit from one of the types found in cast.h 900-1035. I wasn't super sure on the best type to inherit from but, from what I could tell type::type made some sense. If there is some better type to inherit from let me know.

@InvincibleRMC
InvincibleRMC marked this pull request as ready for review June 13, 2024 19:14
@InvincibleRMC

Copy link
Copy Markdown
ContributorAuthor

@rwgk the CI is now passing.

@InvincibleRMC
InvincibleRMC marked this pull request as draft June 13, 2024 21:53
@InvincibleRMC

Copy link
Copy Markdown
ContributorAuthor

With further testing on actual code this does not seem to currently work.

@InvincibleRMC
InvincibleRMC marked this pull request as ready for review June 13, 2024 23:36
@InvincibleRMC

Copy link
Copy Markdown
ContributorAuthor

@rwgk With some updated testing and switching to inheriting from py::object it seems to be all working.

@InvincibleRMC
InvincibleRMC marked this pull request as draft June 13, 2024 23:45
@InvincibleRMC
InvincibleRMC marked this pull request as ready for review June 14, 2024 00:01
@rwgkrwgk changed the title Add type unions and optionals to typing.hAdd Union and Optional to typing.hJun 14, 2024

@rwgkrwgk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I'll run this by other maintainers for a 2nd set of eyes.

Comment threadinclude/pybind11/typing.h
Comment threadinclude/pybind11/typing.h
@rwgk
rwgk merged commit 68405a1 into pybind:masterJun 15, 2024
@github-actionsgithub-actionsBot added the needs changelog Possibly needs a changelog entry label Jun 15, 2024
@henryiiihenryiii changed the title Add Union and Optional to typing.hfeat: add Union and Optional to typing.hJun 23, 2024
@henryiiihenryiii changed the title feat: add Union and Optional to typing.hfeat(typing): add Union and Optional to typing.hJun 23, 2024
@henryiiihenryiii changed the title feat(typing): add Union and Optional to typing.hfeat(types): add Union and Optional to typing.hJun 23, 2024
@henryiiihenryiii removed the needs changelog Possibly needs a changelog entry label Jun 26, 2024
@InvincibleRMC
InvincibleRMC deleted the type-unions branch July 1, 2024 13:47
Sign up for freeto 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

@InvincibleRMC@rwgk@henryiii