python / typing-council

Decisions by the Python Typing Council
41 stars 3 forks source link

Allow unary + in Literal integers #7

Closed JelleZijlstra closed 7 months ago

JelleZijlstra commented 7 months ago

This is to ask the Typing Council to approve python/typing#1550, specifying that Literal[+1] should be allowed. See also https://discuss.python.org/t/signed-values-in-literal-type/39919, cc @dmoisset.

(I'm opening this issue here on this tracker so that we have a clear record of the decision, and people following this repo won't miss it.)

gvanrossum commented 7 months ago

Yup. The symmetry argument makes sense.

hauntsaninja commented 7 months ago

This is reasonable, and pyright, pyre, pytype, mypy (following Jelle's PR) all support it.

erictraut commented 7 months ago

Actually, pyright will need to be modified. It honors the current spec. It's easy to change. Slightly more involved if we decide that we want to support an arbitrary number of unary operators (Literal[---++++-----+++1]), but still pretty straightforward.

hauntsaninja commented 7 months ago

Huh, so it is, sorry about that. I've had https://pyright-play.net/ lag for me once or twice before, maybe that's what happened :-/

gvanrossum commented 7 months ago

Then I suggest that pyright choses to only implement a single + or -. After all that's what was asked for.

JelleZijlstra commented 7 months ago

OK, let's go with that. The outcome is that Literal[+1] is supported, and we leave the behavior of Literal[+-+-+-1] unspecified.