Skip to content

Conversation

@LaBatata101
Copy link
Contributor

Summary

Fixes #18231

Test Plan

Snapshot tests

Comment on lines 94 to 96
let unparenthesized_item_range = parenthesized_range.add_start(1.into()).sub_end(1.into());
let item_str = checker.locator().slice(unparenthesized_item_range);
Edit::range_replacement(item_str.to_string(), expr_call.range())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a better way to unpack the parenthesized expression here? I looked but didn't find any.

When the expression has multiple parenthesis like in:

with open("furb129.py") as f:
    for line in (((f))).readlines():
        pass

the fix will generate this for line in ((f)):, would that be the correct behavior or should it be just f?

Choose a reason for hiding this comment

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

Is it necessary to remove any parentheses? Removing them when fixing for line in(f).readlines() would produce a syntax error, similar to #17683.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it necessary to remove any parentheses?

Not really, I guess.

Choose a reason for hiding this comment

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

Is it necessary to remove any parentheses? Removing them when fixing for line in(f).readlines() would produce a syntax error, similar to #17683.

But for line in f.readlines() is not incorrect syntax. Syntax error itself is for line in(f) block: in is not a function and whitespace should not be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But for line in f.readlines() is not incorrect syntax. Syntax error itself is for line in(f) block: in is not a function and whitespace should not be removed

for line in(f) is not a syntax error, in is lexed as a keyword and not as an identifier, so in(f) is not a function call.

@github-actions
Copy link
Contributor

github-actions bot commented May 20, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre ntBre added bug Something isn't working fixes Related to suggested fixes for violations labels May 28, 2025
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@ntBre ntBre merged commit 04dc48e into astral-sh:main May 28, 2025
34 checks passed
@LaBatata101 LaBatata101 deleted the fix-FURB129 branch May 28, 2025 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fixes Related to suggested fixes for violations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FURB129 fix fails when the variable is parenthesized

4 participants