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 inferring +int to be a Literal #16910

Merged
merged 4 commits into from
Feb 12, 2024

Conversation

TeamSpen210
Copy link
Contributor

This makes unary positive on integers preserve the literal value of the integer, allowing var: Literal[1] = +1 to be accepted. Basically I looked for code handling __neg__ and added a branch for __pos__ as well.
Fixes #16728.

Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@JelleZijlstra JelleZijlstra merged commit c26f129 into python:master Feb 12, 2024
17 of 18 checks passed
@TeamSpen210 TeamSpen210 deleted the literal-positive branch February 24, 2024 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Infer Literal type for + on literal
2 participants