-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 positive for implicit-str-concat
when some but not all strings are raw
#6663
Comments
It make sense. I think the problem existed before we extended this check to |
When working on this, we could check for f-strings mixed with normal strings also. You might terminate an f-string so that it's easier to use |
This is hard to solve as |
Shouldn't we be heading for another direction in solving this? I believe the main intention of this particular check is to prevent accidental concatenation while adding members to a list or tuple, or perhaps indeed also when passing parameters in a function call. For example: COLORS = [
"red"
"yellow",
"blue",
] (note the missing comma after I frequently use implicit string concatenation when breaking up too long strings (to prevent or fix SENTENCES = [
"This is a rather short sentence.",
(
"This is quite a long sentence, having all kinds of additional"
" subordinate clauses, however."
),
"This is another short sentence here.",
] (shown as how So my plea is to only warn for string concatenation when the parts are not collected together in parentheses. For now, I have to generally disable this check, to my regrets, since the |
I think you should open a separate issue for this. This is mainly about concatenating different types. |
Yeah you're right, I discovered that my issue is substantially different (is more about that I've activated (Although my remark could provide some sort of work-around for this issue as well? ...) |
I don't want to spoil things, but I can't refrain myself from popping up the following philosophical question: how does pylint know that the string concatenation was intentional? Suppose you're building up a list, where each digit (as) text is preceded by a backslash and you rely on your knowledge that you know what backslash/character combinations are interpreted as a escape sequences and what are not (perhaps not the best coding practice, but anyways): my_digits = ["\zero", "\one", r"\two", r"\three", r"\four", r"\five" "\six", "\seven", "\eight", r"\nine"] With this issue's proposed solution, this erroneous code would pass without a complaint, since it will not complain about the missing comma between |
We favor false negatives, so this is a trade off I think we should make. There's two problem in |
Yes, I should have come up with a better example, but I think we can come up with examples where it is completely logical to enter one value within a list of strings as a raw string, and another as a plain string, and perhaps a third as an f-string. A missing comma in those situations doesn't automatically imply that the concatenation is intentional. [[[
]]] Anyhow, that's another issue. As stated earlier, given the example at the top of this issue, I would propose to "solve" it by allowing implicit string concatenation if and only if you surround it with a set of parentheses (as a signal to your linter that the concatenation is intentional), as in: import unittest
class MyTest(unittest.TestCase):
def testColors(self):
self.assertEqual(
self.string_output(),
(r'\override Stem.color = "darkgreen"' '\n')
) (ref. #7929) If I'm not mistaken, the |
Bug description
I don't think
implicit-str-concat
is a useful warning when the reason for breaking and restarting the string is to start or stop treating a portion of a string as a raw string. (As I understand it, we're trying to catch someone forgetting a comma between arguments.)For instance, this string needs to escape
\o
but not\n
:Configuration
No response
Command used
Pylint output
Expected behavior
no msg
Pylint version
OS / Environment
No response
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: