Skip to content

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

Merged
AlexWaygood merged 4 commits intoastral-sh:mainfrom
dylwil3:decimal
Sep 7, 2024
Merged

[ruff] Handle unary operators in decimal-from-float-literal (RUF032)#13275
AlexWaygood merged 4 commits intoastral-sh:mainfrom
dylwil3:decimal

Conversation

@dylwil3
Copy link
Copy Markdown
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
@github-actions
Copy link
Copy Markdown
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
Copy Markdown
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
@dylwil3
Copy link
Copy Markdown
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