-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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) C++ int and bool Literals in Python Literal Type #5463
base: master
Are you sure you want to change the base?
feat(types) C++ int and bool Literals in Python Literal Type #5463
Conversation
Failing test is unrelated see #5464. |
typedef py::typing::Literal<26, | ||
0x14, | ||
py::typing::StringLiteral("\"hello world\""), | ||
py::typing::StringLiteral("b\"hello world\""), | ||
py::typing::StringLiteral("u\"hello world\""), | ||
true, | ||
py::typing::StringLiteral("Color.RED"), | ||
py::typing::StringLiteral("None")> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just skimming over this, but would a simple string literal than have to use:
py::typing::Literal<py::typing::StringLiteral("hello")>
?
Would be nice if strings could be used directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What could be done I believe is only allow each Literal of the same type. Then I don't think you would need the py::typing::Literal<py::typing::StringLiteral("hello")>
however, you wouldn't be able to mix non-type templates inside Literals and would need to use Unions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After messing around with various solutions the only one I could get working is make different named literals.
py::typing::LiteralString"Hi">
py::typing::LiteralInt<1, 2, 3>
py::typing::LiteralBool<true>
To avoid confusion if we wanted to move forward with this the current typing::StringLiteral
would be change to typing::fixed_string
.
efdf223
to
046277e
Compare
Description
typing.Literal
now can accept straight ints and bools, rather than only string Literals previously. For more information check out the python pep here.Suggested changelog entry:
Update `typing.Literal` type to support C++ ints and bools