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

red-knot: implement unary minus on integer literals #13114

Merged

Conversation

chriskrycho
Copy link
Contributor

Summary

Add support for the first unary operator: negating integer literals. The resulting type is another integer literal, with the value being the negated value of the literal. All other types continue to return Type::Unknown for the present, but this is designed to make it easy to extend easily with other combinations of operator and operand.

Contributes to #12701.

Test Plan

Add tests with basic negation, including of very large integers and double negation.

Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

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

Looks great!

Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@carljm carljm merged commit fe8b152 into astral-sh:main Aug 26, 2024
20 checks passed
@chriskrycho chriskrycho deleted the rk-infer-unary-negate-int-literal branch August 26, 2024 19:08
@carljm carljm added the red-knot Multi-file analysis & type inference label Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants