Skip to content

Detect literals with unary operators (UP018)#10060

Merged
charliermarsh merged 3 commits into
astral-sh:mainfrom
sanxiyn:UP018-fix
Feb 20, 2024
Merged

Detect literals with unary operators (UP018)#10060
charliermarsh merged 3 commits into
astral-sh:mainfrom
sanxiyn:UP018-fix

Conversation

@sanxiyn
Copy link
Copy Markdown
Contributor

@sanxiyn sanxiyn commented Feb 20, 2024

Fix #10029.

@charliermarsh charliermarsh added the bug Something isn't working label Feb 20, 2024
@charliermarsh charliermarsh self-requested a review February 20, 2024 16:03
Comment on lines +231 to +234
if unary {
if !matches!(literal_type, LiteralType::Int | LiteralType::Float) {
return;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would you mind adding a comment why this check is necessary for unary only and add a test case that verifies that ruff early returns if it's an unary and neither an Int nor Float

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I moved this up into the match.

@charliermarsh charliermarsh enabled auto-merge (squash) February 20, 2024 18:12
@charliermarsh charliermarsh merged commit 7eafba2 into astral-sh:main Feb 20, 2024
@github-actions
Copy link
Copy Markdown
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

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.

UP018 doesn't detect integers literals used with unary operators

3 participants