pybind / pybind11

Seamless operability between C++11 and Python
https://pybind11.readthedocs.io/
Other
15.55k stars 2.09k forks source link

feat(types): add support for typing.Literal type #5192

Closed InvincibleRMC closed 3 months ago

InvincibleRMC commented 3 months ago

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`.
rwgk commented 3 months ago

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 commented 3 months ago

Twine is broken. Working on fix at https://github.com/pypa/twine/pull/1126.

henryiii commented 3 months ago

And I'm avoiding the breakage at #5196.