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

Allow unary + in integer Literals #1551

Open
dmoisset opened this issue Dec 25, 2023 · 1 comment
Open

Allow unary + in integer Literals #1551

dmoisset opened this issue Dec 25, 2023 · 1 comment
Labels
topic: feature Discussions about new features for Python's type annotations

Comments

@dmoisset
Copy link
Contributor

Currently a declaration sign: Literal[-1, +1] is not allowed, because the spec forbids expressions as literal values. There is an explicit exception for unary minus, but no corresponding exception for unary plus.

Even if the issue can be easily worked around (by declaring something like sign: Literal[-1, 1]), the original version is more clear, because in some domains explicitly specifying the sign of positive numbers is more natural. Allowing a unary plus wouldn't just be more consistent, but would enhance clarity, and the impact on other users and on type-checker implementers would be quite small.

PR with proposed change: #1550

Note: discussed on https://discuss.python.org/t/signed-values-in-literal-type/39919

@dmoisset dmoisset added the topic: feature Discussions about new features for Python's type annotations label Dec 25, 2023
@JelleZijlstra
Copy link
Member

Thanks, this looks reasonable. As a next step, could you open an issue on the typing-council repo following the numbered steps in https://github.com/python/typing-council?tab=readme-ov-file#decisions ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: feature Discussions about new features for Python's type annotations
Projects
None yet
Development

No branches or pull requests

2 participants