You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
String concatenation by juxtaposition is bad both in theory and practice. Pylint should when seeing it warn the user and suggest explicit concatenation using the + operator.
Philosophy: String concatenation by juxtaposition breaks referential transparency
A foundational principle of computer science and programming languages is referential transparency, which states that for expressions that do not have side effects, replacing one expression that evaluates to a given value by another expression that evaluates to the same value has no effect on program behavior. Were referential transparency respected
my_string='abc''xyz'
and
my_prefix='abc'my_string=my_prefix'xyz'
would assign the same value to my_string. Because string-concatenation-by-juxtaposition is a language misfeature that violates referential transparency, the former code assigns the value 'abcxyz' to my_string and the latter code raises a SyntaxError. Yuck.
Pragmatism: String concatenation by juxtaposition fosters defects
I don't know a Python programmer who hasn't at some point accidentally written some form of
Hey @nathanielmanistaatgoogle Thanks for creating the issue. We already have this check under the name of implicit-str-concat-in-sequence. Unfortunately it's specific to sequences, but I could definitely see it useful for the assignment case as well. For multi-line jumps you'd have to run pylint with --check-str-concat-over-line-jumps=y, since by default it looks for occurrences on the same line.
Thanks for the report, this is fixed now in master and will be part of 2.5. For multiline juxtaposition, you need to pass --check-str-concat-over-line-jumps=y or set it in the configuration file.
String concatenation by juxtaposition is bad both in theory and practice. Pylint should when seeing it warn the user and suggest explicit concatenation using the
+
operator.Philosophy: String concatenation by juxtaposition breaks referential transparency
A foundational principle of computer science and programming languages is referential transparency, which states that for expressions that do not have side effects, replacing one expression that evaluates to a given value by another expression that evaluates to the same value has no effect on program behavior. Were referential transparency respected
and
would assign the same value to
my_string
. Because string-concatenation-by-juxtaposition is a language misfeature that violates referential transparency, the former code assigns the value'abcxyz'
tomy_string
and the latter code raises aSyntaxError
. Yuck.Pragmatism: String concatenation by juxtaposition fosters defects
I don't know a Python programmer who hasn't at some point accidentally written some form of
and then (depending on the circumstances) taken some time to find the bug.
The text was updated successfully, but these errors were encountered: