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

[ruff] Handle unary operators in decimal-from-float-literal (RUF032) #13275

Merged
merged 4 commits into from
Sep 7, 2024

Conversation

dylwil3
Copy link
Collaborator

@dylwil3 dylwil3 commented Sep 7, 2024

This PR ensures that the suggested "stringified" float passed to decimal.Decimal does not contain more than one unary operator, and that the rule ignores floats with the invalid unary operators ~ and not. For example,

Decimal(- + - + - +4.0)

has a suggested fix of Decimal("-4.0").

Closes #13258

@dylwil3 dylwil3 changed the title [ruff] Handle unary operators in decimal-from-float-literal (RUF032) [ruff] Handle unary operators in decimal-from-float-literal (RUF032) Sep 7, 2024
Copy link
Contributor

github-actions bot commented Sep 7, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thanks! I pushed a commit to reduce the amount of cloning of AST nodes, which can be quite expensive. I also made a few other small simplifications -- let me know if you have any questions about the changes I pushed!

@AlexWaygood AlexWaygood enabled auto-merge (squash) September 7, 2024 13:24
@AlexWaygood AlexWaygood merged commit a7c9368 into astral-sh:main Sep 7, 2024
17 checks passed
@dylwil3
Copy link
Collaborator Author

dylwil3 commented Sep 7, 2024

I was wondering how to do something like that, so that's super helpful to see - thanks for making the code much nicer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RUF032 fix can produce strings that are invalid for Decimal
3 participants