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

Flag superfluous-parens if parentheses are used during string concatenation. #7752

Merged
merged 6 commits into from Nov 13, 2022

Conversation

clavedeluna
Copy link
Collaborator

@clavedeluna clavedeluna commented Nov 11, 2022

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Closes #4792

This PR ensures that superfluous-parens is emitted if str concatenation is happening but the parentheses are not necessary, that is without the parens the concat result is the same as with them.

hi = ("CONST",)

#TODO: maybe get this line to report [superfluous-parens] without causing other false positives.
assert "" + ("Version " + "String") in Z
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright so this is a legitimate case for raising superlous-parens and was brought up in the issue, but I cannot fix it without causing other bigger issues. I think it's probably ok to leave this as a false negative?

@clavedeluna clavedeluna marked this pull request as ready for review November 11, 2022 17:14
@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component False Negative πŸ¦‹ No message is emitted but something is wrong with the code labels Nov 11, 2022
@jacobtylerwalls
Copy link
Member

Do you know what's up with the alternative-union-syntax test failure?

@clavedeluna
Copy link
Collaborator Author

clavedeluna commented Nov 12, 2022

Do you know what's up with the alternative-union-syntax test failure?

Fixed. Disabling superfulous-parens in alternative_union_syntax:52 is reasonable given that we aren't testing for that, but also the msg being raised is also correct there bc

CustomTypedDict = TypedDict("CustomTypedDict", my_var=(int | str))

==

CustomTypedDict = TypedDict("CustomTypedDict", my_var=int | str)

@coveralls
Copy link

coveralls commented Nov 12, 2022

Pull Request Test Coverage Report for Build 3455686088

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.004%) to 95.401%

Files with Coverage Reduction New Missed Lines %
pylint/checkers/refactoring/refactoring_checker.py 3 97.97%
Totals Coverage Status
Change from base Build 3455107107: -0.004%
Covered Lines: 17323
Relevant Lines: 18158

πŸ’› - Coveralls

@github-actions

This comment has been minimized.

@clavedeluna
Copy link
Collaborator Author

I looked at some of the primer outputs and it actually seems like this is working exactly as we want!

Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's not a big scope change to add :=, so marking request changes for now. I think you'll need to create a new test file with min_pyver=3.8 in the corresponding .rc file, which you can find examples of.

@github-actions

This comment has been minimized.

@jacobtylerwalls
Copy link
Member

Sorry, one more thing. You could change the news fragment to end with false_negative, which will ensure it gets organized in the release notes with the other false negatives automagically.

@jacobtylerwalls jacobtylerwalls enabled auto-merge (squash) November 13, 2022 14:45
@jacobtylerwalls jacobtylerwalls merged commit 80a9d4a into pylint-dev:main Nov 13, 2022
@github-actions
Copy link
Contributor

πŸ€– Effect of this PR on checked open source code: πŸ€–

Effect on django:
The following messages are now emitted:

  1. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/django/django/blob/1be7e36f85c927560e8c3c1eda05a7e43a66cd22/django/contrib/admin/helpers.py#L156

Effect on music21:
The following messages are now emitted:

  1. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/tempo.py#L1266
  2. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/tablature.py#L242
  3. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/voiceLeading.py#L192
  4. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/roman.py#L1031
  5. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/roman.py#L3141
  6. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/roman.py#L3455
  7. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/musicxml/test_xmlToM21.py#L1281
  8. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/musicxml/m21ToXml.py#L3557
  9. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/musicxml/m21ToXml.py#L3800
  10. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/musicxml/m21ToXml.py#L4635
  11. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/musicxml/test_m21ToXml.py#L65
  12. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/chord/tables.py#L550
  13. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/stream/base.py#L4626
  14. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/midi/__init__.py#L821
  15. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/test/commonTest.py#L112
  16. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/test/testSingleCoreAll.py#L103
  17. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/alpha/analysis/hasher.py#L436
  18. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/braille/test.py#L1157
  19. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/graph/primitives.py#L1006
  20. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/figuredBass/segment.py#L425
  21. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/figuredBass/segment.py#L426
  22. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/romanText/translate.py#L543
  23. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/romanText/translate.py#L696
  24. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/analysis/reduction.py#L600
  25. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/analysis/reduction.py#L855
  26. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/meter/base.py#L558
  27. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/meter/base.py#L1368
  28. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/meter/base.py#L1369
  29. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/cuthbertLab/music21/blob/6c1e5705b2140443b27cebfaa75826fde9dfe870/music21/meter/base.py#L1682

Effect on pandas:
The following messages are now emitted:

  1. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/_testing/__init__.py#L341
  2. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/strings/test_extract.py#L555
  3. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/reshape/concat/test_append.py#L94
  4. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/reshape/concat/test_append.py#L97
  5. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/frame/constructors/test_from_records.py#L252
  6. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/arrays/categorical/test_operators.py#L329
  7. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/plotting/test_series.py#L840
  8. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/test_html.py#L255
  9. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_to_xml.py#L452
  10. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_to_xml.py#L457
  11. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_to_xml.py#L494
  12. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_to_xml.py#L499
  13. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_to_xml.py#L743
  14. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_to_xml.py#L865
  15. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_to_xml.py#L1078
  16. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_to_xml.py#L1107
  17. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_to_xml.py#L1127
  18. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_xml.py#L545
  19. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_xml.py#L556
  20. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_xml.py#L573
  21. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_xml.py#L672
  22. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_xml.py#L678
  23. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_xml.py#L687
  24. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_xml.py#L950
  25. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_xml.py#L957
  26. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_xml.py#L966
  27. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_xml.py#L984
  28. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_xml.py#L990
  29. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_xml.py#L1192
  30. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_xml.py#L1254
  31. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_xml.py#L1276
  32. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_xml_dtypes.py#L284
  33. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_xml_dtypes.py#L290
  34. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/tests/io/xml/test_xml_dtypes.py#L298
  35. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/pandas-dev/pandas/blob/e7b044c558c7f763055b8ac1be359dcf787712bf/pandas/io/stata.py#L328

Effect on sentry:
The following messages are now emitted:

  1. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/getsentry/sentry/blob/b5ff5b6e8a24f4e7af273f0fa0f9274f205f21d0/src/sentry/tasks/integrations/migrate_issues.py#L22
  2. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/getsentry/sentry/blob/b5ff5b6e8a24f4e7af273f0fa0f9274f205f21d0/src/sentry/tasks/integrations/create_comment.py#L15
  3. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/getsentry/sentry/blob/b5ff5b6e8a24f4e7af273f0fa0f9274f205f21d0/src/sentry/tasks/integrations/update_comment.py#L15
  4. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/getsentry/sentry/blob/b5ff5b6e8a24f4e7af273f0fa0f9274f205f21d0/src/sentry/runner/commands/cleanup.py#L249

Effect on coverage:
The following messages are now emitted:

  1. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/nedbat/coveragepy/blob/bb5935b2845d80d26b62eaa0dc6eed4f0470ba22/coverage/env.py#L16
  2. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/nedbat/coveragepy/blob/bb5935b2845d80d26b62eaa0dc6eed4f0470ba22/coverage/env.py#L17
  3. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/nedbat/coveragepy/blob/bb5935b2845d80d26b62eaa0dc6eed4f0470ba22/coverage/env.py#L18
  4. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/nedbat/coveragepy/blob/bb5935b2845d80d26b62eaa0dc6eed4f0470ba22/coverage/env.py#L19
  5. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/nedbat/coveragepy/blob/bb5935b2845d80d26b62eaa0dc6eed4f0470ba22/coverage/env.py#L69
  6. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/nedbat/coveragepy/blob/bb5935b2845d80d26b62eaa0dc6eed4f0470ba22/coverage/env.py#L85
  7. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/nedbat/coveragepy/blob/bb5935b2845d80d26b62eaa0dc6eed4f0470ba22/coverage/env.py#L108
  8. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/nedbat/coveragepy/blob/bb5935b2845d80d26b62eaa0dc6eed4f0470ba22/coverage/env.py#L111
  9. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/nedbat/coveragepy/blob/bb5935b2845d80d26b62eaa0dc6eed4f0470ba22/coverage/env.py#L114
  10. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/nedbat/coveragepy/blob/bb5935b2845d80d26b62eaa0dc6eed4f0470ba22/coverage/env.py#L118
  11. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/nedbat/coveragepy/blob/bb5935b2845d80d26b62eaa0dc6eed4f0470ba22/coverage/summary.py#L247
  12. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/nedbat/coveragepy/blob/bb5935b2845d80d26b62eaa0dc6eed4f0470ba22/coverage/summary.py#L248
  13. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/nedbat/coveragepy/blob/bb5935b2845d80d26b62eaa0dc6eed4f0470ba22/coverage/config.py#L518
  14. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/nedbat/coveragepy/blob/bb5935b2845d80d26b62eaa0dc6eed4f0470ba22/coverage/templite.py#L160
  15. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/nedbat/coveragepy/blob/bb5935b2845d80d26b62eaa0dc6eed4f0470ba22/coverage/html.py#L288
  16. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/nedbat/coveragepy/blob/bb5935b2845d80d26b62eaa0dc6eed4f0470ba22/coverage/html.py#L289
  17. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/nedbat/coveragepy/blob/bb5935b2845d80d26b62eaa0dc6eed4f0470ba22/coverage/pytracer.py#L188
  18. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/nedbat/coveragepy/blob/bb5935b2845d80d26b62eaa0dc6eed4f0470ba22/coverage/pytracer.py#L190
  19. superfluous-parens:
    Unnecessary parens after '=' keyword
    https://github.com/nedbat/coveragepy/blob/bb5935b2845d80d26b62eaa0dc6eed4f0470ba22/coverage/pytracer.py#L219

This comment was generated for commit a456d02

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component False Negative πŸ¦‹ No message is emitted but something is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make superfluous-parens consider string combinations
5 participants