typing icon indicating copy to clipboard operation
typing copied to clipboard

Allow unary `+` in integer Literals

Open dmoisset opened this issue 2 years ago • 1 comments

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 avatar Dec 25 '23 17:12 dmoisset

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 ?

JelleZijlstra avatar Jan 02 '24 02:01 JelleZijlstra