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 Literal integers #7

Closed
JelleZijlstra opened this issue Jan 12, 2024 · 6 comments
Closed

Allow unary + in Literal integers #7

JelleZijlstra opened this issue Jan 12, 2024 · 6 comments
Labels

Comments

@JelleZijlstra
Copy link
Member

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
Copy link
Member

Yup. The symmetry argument makes sense.

@hauntsaninja
Copy link
Collaborator

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

@erictraut
Copy link
Collaborator

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
Copy link
Collaborator

hauntsaninja commented Jan 12, 2024

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
Copy link
Member

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

@JelleZijlstra
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants