Skip to content

Conversation

@prakhar1144
Copy link
Contributor

Summary

As reported in #19757:
While attempting ISC003 autofix for an expression with explicit string concatenation, with either operand being a string literal that wraps across multiple lines (in parentheses) - it resulted in generating a fix which caused runtime error.

Example:

_ = "abc" + (
    "def"
    "ghi"
)

was being auto-fixed to:

_ = "abc" (
    "def"
    "ghi"
)

which raised TypeError: 'str' object is not callable

This commit makes changes to just report diagnostic - no autofix in such cases.

Fixes #19757.

Test Plan

Added example scenarios in crates/ruff_linter/resources/test/fixtures/flake8_implicit_str_concat/ISC.py.

@prakhar1144
Copy link
Contributor Author

As per suggestion in #19778 (comment):

I think we can probably just use this helper function to check if left and right are parenthesized and avoid the fix if either of them is

We can also still report a diagnostic in this case, we just can't autofix it. Another option would be to try to move one of the expressions into the existing parentheses from the other expression, but that might be too involved. I'd be happy with just offering a diagnostic but no fix if one of them is parenthesized to avoid causing the runtime error.

@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 18, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@prakhar1144 prakhar1144 marked this pull request as ready for review November 18, 2025 22:08
@amyreese amyreese added bug Something isn't working fixes Related to suggested fixes for violations labels Nov 19, 2025
…ISC003)

As reported in astral-sh#19757:
While attempting ISC003 autofix for an expression with explicit string
concatenation, with either operand being a string literal that wraps
across multiple lines (in parentheses) - it resulted in generating
a fix which caused runtime error.

Example:
_ = "abc" + (
    "def"
    "ghi"
)
was being auto-fixed to:
_ = "abc" (
    "def"
    "ghi"
)
which raised `TypeError: 'str' object is not callable`

This commit makes changes to just report diagnostic - no autofix
in such cases.

Fixes astral-sh#19757.

Signed-off-by: Prakhar Pratyush <[email protected]>
@prakhar1144 prakhar1144 marked this pull request as draft November 19, 2025 15:31
@prakhar1144 prakhar1144 marked this pull request as ready for review November 19, 2025 16:03
@prakhar1144 prakhar1144 requested a review from amyreese November 19, 2025 16:03
@prakhar1144
Copy link
Contributor Author

This is ready to review.

@amyreese amyreese changed the title [flake8-implicit-str-concat] Avoid invalid fix generated by autofix (ISC003) [flake8-implicit-str-concat] Avoid invalid fix generated by autofix (ISC003) Nov 22, 2025
@amyreese amyreese merged commit 492d676 into astral-sh:main Nov 22, 2025
37 checks passed
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.

Autofix for ISC003 produces malformed code

2 participants