KEMBAR78
Allow inferring +int to be a Literal by TeamSpen210 · Pull Request #16910 · python/mypy · GitHub
Skip to content

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.

@github-actions
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
@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