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

Pylint does not escape strings before outputting them in messages #7874

Closed
GideonBear opened this issue Nov 30, 2022 · 5 comments · Fixed by #9164
Closed

Pylint does not escape strings before outputting them in messages #7874

GideonBear opened this issue Nov 30, 2022 · 5 comments · Fixed by #9164
Labels
Bug 🪲 Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@GideonBear
Copy link
Contributor

Bug description

var == '\n'

I confirmed this happens in magic-value, but I don't know if there are other errors that this can apply to.
Maybe it should use repr instead of str for representing values?
This also happens with other characters:

  • '\r': '. (magic-value-comparison) R2004: Consider using a named constant or an enum instead of '
  • Any color code (for example '\033[92m'): Everything after instead of ' is colored green

Configuration

[MAIN]
load-plugins=pylint.extensions.magic_value

Command used

pylint a.py

Pylint output

R2004: Consider using a named constant or an enum instead of '
'. (magic-value-comparison)

Expected behavior

R2004: Consider using a named constant or an enum instead of '\n'. (magic-value-comparison)

Pylint version

pylint 2.16.0-dev
astroid 2.12.13
Python 3.9.15 (main, Nov 11 2022, 13:33:56) 
[GCC 9.4.0]

OS / Environment

No response

Additional dependencies

No response

@GideonBear GideonBear added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Nov 30, 2022
@clavedeluna
Copy link
Contributor

Can reproduce!

@clavedeluna clavedeluna added Bug 🪲 and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Nov 30, 2022
@Pierre-Sassoulas Pierre-Sassoulas added the Needs PR This issue is accepted, sufficiently specified and now needs an implementation label Nov 30, 2022
@GideonBear
Copy link
Contributor Author

@Pierre-Sassoulas
Copy link
Member

Probably with left_operand.as_string() and right_operand.as_string().

@GideonBear
Copy link
Contributor Author

Are there more checkers where this needs to be fixed?

@Pierre-Sassoulas
Copy link
Member

Not sure; but possibly as we're trying more and more to add code suggestions in messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants