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

Escape special symbols and newlines in messages. #9164

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/7874.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Escape special symbols and newlines in messages.

Closes #7874
4 changes: 2 additions & 2 deletions pylint/extensions/magic_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def _check_constants_comparison(self, node: nodes.Compare) -> None:

operand_value = None
if const_operands[LEFT_OPERAND] and self._is_magic_value(left_operand):
operand_value = left_operand.value
operand_value = left_operand.as_string()
elif const_operands[RIGHT_OPERAND] and self._is_magic_value(right_operand):
operand_value = right_operand.value
operand_value = right_operand.as_string()
if operand_value is not None:
self.add_message(
"magic-value-comparison",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ class Christmas(Enum):

shouldnt_raise = var == '\n'
shouldnt_raise = var == '\\b'

should_escape = var == "foo\nbar" # [magic-value-comparison]
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ comparison-of-constants:24:17:24:22::"Comparison between constants: '5 > 7' has
singleton-comparison:29:17:29:28::Comparison 'var == True' should be 'var is True' if checking for the singleton value True, or 'bool(var)' if testing for truthiness:UNDEFINED
singleton-comparison:30:17:30:29::Comparison 'var == False' should be 'var is False' if checking for the singleton value False, or 'not var' if testing for falsiness:UNDEFINED
singleton-comparison:31:17:31:28::Comparison 'var == None' should be 'var is None':UNDEFINED
magic-value-comparison:38:16:38:33::Consider using a named constant or an enum instead of ''foo\nbar''.:HIGH
Loading