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

Add check for redundant u prefixed string in Python 3 #4102

Closed
federicobond opened this issue Feb 16, 2021 · 4 comments · Fixed by #4804
Closed

Add check for redundant u prefixed string in Python 3 #4102

federicobond opened this issue Feb 16, 2021 · 4 comments · Fixed by #4804
Assignees
Labels
Checkers Related to a checker Enhancement ✨ Improvement to a component
Milestone

Comments

@federicobond
Copy link
Contributor

Is your feature request related to a problem? Please describe

In Python 3, the u prefix is no longer necessary to indicate that a string is unicode, but some programmers may put it there out of habit or because they copied the code from somewhere else.

Describe the solution you'd like

Pylint should flag instances of u-prefixed strings in Python 3 with the redundant-string-prefix code.


I can contribute this check if there is interest in it.

@Pierre-Sassoulas Pierre-Sassoulas added Checkers Related to a checker Enhancement ✨ Improvement to a component labels Feb 16, 2021
@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented Feb 16, 2021

This sound reasonable; maybe redundant-u-string-prefix would be clearer ? Also, this should probably tell the user to run 2to3 because I think 2to3 removes that prefix. Maybe the reason why the check is not implemented yet in pylint ?

@federicobond
Copy link
Contributor Author

This sound reasonable; maybe redundant-u-string-prefix would be clearer ?

I was thinking about leaving the door open to check for f-strings without interpolation and maybe other cases.

Also, this should probably tell the user to run 2to3 because I think 2to3 removes that prefix. Maybe the reason why the check is not implemented yet in pylint ?

For projects that have already been translated to Python 3, 2to3 is not very useful and I believe many would prefer to just remove the prefix manually once it's flagged by the linter.

@Pierre-Sassoulas
Copy link
Member

Ok, it makes sense for those that did not run 2to3 in the past.

We already have a message for f-string without interpolation :) : W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation)

@DanielNoord
Copy link
Collaborator

You can assign this to me. However, I would like to have #4787 first because I would include it in the visit_const function add on line 903 there.

DanielNoord added a commit to DanielNoord/pylint that referenced this issue Aug 5, 2021
This adds a checker for u-prefixes for strings, as used in Python 2.
Closes pylint-dev#4102
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.10.0 milestone Aug 5, 2021
Pierre-Sassoulas pushed a commit that referenced this issue Aug 6, 2021
* Add ``redundant-u-string-prefix`` checker
This adds a checker for u-prefixes for strings, as used in Python 2. It only work in python 3.8 and above.
Closes #4102
return42 added a commit to searxng/searxng that referenced this issue Aug 31, 2021
Pylint 2.10 added new default checks [1]:

redundant-u-string-prefix:
  Emitted when the u prefix is added to a string

[1] https://pylint.pycqa.org/en/latest/whatsnew/2.10.html
[2] pylint-dev/pylint#4102

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
stanislavlevin added a commit to stanislavlevin/freeipa-healthcheck that referenced this issue Feb 15, 2022
Pylint 2.10 introduced new checker `redundant-u-string-prefix`:
> Added redundant-u-string-prefix checker: Emitted when the u prefix is
  added to a string

https://pylint.pycqa.org/en/latest/whatsnew/changelog.html#what-s-new-in-pylint-2-10-0
pylint-dev/pylint#4102

Fixes: freeipa#244
Signed-off-by: Stanislav Levin <slev@altlinux.org>
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants