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 support for typing.Literal type #5192

Merged
merged 77 commits into from
Jun 25, 2024

Conversation

InvincibleRMC
Copy link
Contributor

@InvincibleRMC InvincibleRMC commented Jun 24, 2024

Description

Implements support for typing.Literal

Example declaration.

typedef py::typing::Literal<"26", "0x1A", "\"hello world\"", "b\"hello world\"", "u\"hello world\"", "True", "Color.RED", "None"> LiteralFoo;

Allows more narrow return types of python objects.

def foo(number: int) -> None: ...

def foo(one_or_two: Literal[1, 2]) -> None: ...

Suggested changelog entry:

   Adds support for `typing.Literal`.

char name[N];
};

// NOTE: C++ implemented constant template Literal[1, 2] does not equal Literal[2, 1]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could this be simplified?

// NOTE: Literal[1, 2] does not equal Literal[2, 1]

But why is this noteworthy here? (IOW, where/why does it matter?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops this comment was left from a previous implementation. It has now been removed.

@henryiii henryiii changed the title Add support for typing.Literal type feat: add support for typing.Literal type Jun 25, 2024
@henryiii henryiii changed the title feat: add support for typing.Literal type feat(types): add support for typing.Literal type Jun 25, 2024
Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

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

I'll merge it as soon as I see that the GHA are done.

@rwgk
Copy link
Collaborator

rwgk commented Jun 25, 2024

Don't worry about this failure: Pip / 🐍 3.8 • 📦 & 📦 tests • ubuntu-latest

It's just some kind of infrastructure hiccup that we can safely ignore here. (Similar hiccups happen all the time.)

@henryiii
Copy link
Collaborator

Twine is broken. Working on fix at pypa/twine#1126.

@henryiii henryiii merged commit 183059f into pybind:master Jun 25, 2024
82 of 84 checks passed
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Jun 25, 2024
@InvincibleRMC InvincibleRMC deleted the Literal-type branch June 25, 2024 21:57
@henryiii
Copy link
Collaborator

And I'm avoiding the breakage at #5196.

@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Jun 26, 2024
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.

None yet

3 participants