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

False negatives for implicit string concatenation #6441

Closed
Pierre-Sassoulas opened this issue Apr 22, 2022 · 3 comments · Fixed by #6443
Closed

False negatives for implicit string concatenation #6441

Pierre-Sassoulas opened this issue Apr 22, 2022 · 3 comments · Fixed by #6443
Labels
Checkers Related to a checker Enhancement ✨ Improvement to a component False Negative 🦋 No message is emitted but something is wrong with the code
Milestone

Comments

@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented Apr 22, 2022

Current problem

The following code:

print("Lorem ipsum " "dolor sit amet")

Could be rewritten:

print("Lorem ipsum dolor sit amet")

But

print(
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit,"
    " sed do eiusmod tempor incididunt ut labore et dolore "
    "magna aliqua. Ut enim ad minim veniam, quis nostrud "
    "exercitation ullamco laboris nisi ut aliquip ex ea "
)

Should not, because the implicit string concatenation is not useless as removing it would make the line go over the max line length.

Desired solution

Raise implicit-str-concat in this situation.

Additional context

pylint-dev/astroid#1525 (comment)

@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component Checkers Related to a checker False Negative 🦋 No message is emitted but something is wrong with the code labels Apr 22, 2022
@Pierre-Sassoulas
Copy link
Member Author

A decision was made in fcc0151 to not raise implicit-str-concat on function call, I don't understand the rationale.

Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Apr 23, 2022
@Pierre-Sassoulas Pierre-Sassoulas changed the title New checker for useless implicit string concatenation False negatives for implicit string concatenation Apr 23, 2022
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Apr 23, 2022
@cdce8p
Copy link
Member

cdce8p commented Apr 23, 2022

A decision was made in fcc0151 to not raise implicit-str-concat on function call, I don't understand the rationale.

Saw this comment about it: #1655 (comment)

@Pierre-Sassoulas
Copy link
Member Author

Pierre-Sassoulas commented Apr 23, 2022

We have the option check-str-concat-over-line-jump to handle multi line implicit str concat though, the example in this comment would be treated well. Also I think I have a good example of a call being faulty if you consider:

with open("file.txt" "r", encoding="utf8") as f:
    content = f.read()

print is a bad example as the implicit str concat happens anyway.

Also seeing #1655 (comment) I think not including calls is an oversight too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Checkers Related to a checker Enhancement ✨ Improvement to a component False Negative 🦋 No message is emitted but something is wrong with the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants