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

Black causes W1404 Implicit string concatenation found in assignment (implicit-str-concat) #1837

Closed
vertti opened this issue Nov 23, 2020 · 6 comments
Labels
T: bug Something isn't working

Comments

@vertti
Copy link

vertti commented Nov 23, 2020

Describe the bug

When Black decides a multiline string can be put to single line, it leaves the concatenation in place rather than merging them to a single string. This is considered a bug pattern by Pylint and does seem to be a bug rather than a feature from Black.

To Reproduce Steps to reproduce the behavior:

Having code something like this:

foo = (
  "not really super long line "
  "but enough that I split it"
)

will, when line length allows, be pulled by Black to:

foo = "not really super long line " "but enough that I split it"

rather than a single string.

Expected behavior

In the above situation I would have expected the result to be:

foo = "not really super long line but enough that I split it"

instead of single-line implicit concatenation that is by default flagged by Pylint (W1404)

**Environment **

  • Version: master
  • OS and Python version: Ubuntu 20.10, Python 3.8.5

Does this bug also happen on master?

Yes

@vertti vertti added the T: bug Something isn't working label Nov 23, 2020
@JelleZijlstra
Copy link
Collaborator

I believe the --experimental-string-processing flag fixes this (we'll turn this on by default once it's stable enough).

@vertti
Copy link
Author

vertti commented Dec 7, 2020

Excellent. Thanks!

@vertti vertti closed this as completed Dec 7, 2020
sergiitk added a commit to grpc/grpc that referenced this issue Jun 9, 2023
- Switched  from yapf to black
- Reconfigure isort for black
- Resolve black/pylint idiosyncrasies 

Note: I used `--experimental-string-processing` because black was
producing "implicit string concatenation", similar to what described
here: psf/black#1837. While currently this
feature is experimental, it will be enabled by default:
psf/black#2188. After running black with the
new string processing so that the generated code merges these `"hello" "
world"` strings concatenations, then I removed
`--experimental-string-processing` for stability, and regenerated the
code again.

To the reviewer: don't even try to open "Files Changed" tab 😄 It's
better to review commit-by-commit, and ignore `run black and isort`.
mario-vimal pushed a commit to mario-vimal/grpc that referenced this issue Jun 15, 2023
- Switched  from yapf to black
- Reconfigure isort for black
- Resolve black/pylint idiosyncrasies 

Note: I used `--experimental-string-processing` because black was
producing "implicit string concatenation", similar to what described
here: psf/black#1837. While currently this
feature is experimental, it will be enabled by default:
psf/black#2188. After running black with the
new string processing so that the generated code merges these `"hello" "
world"` strings concatenations, then I removed
`--experimental-string-processing` for stability, and regenerated the
code again.

To the reviewer: don't even try to open "Files Changed" tab 😄 It's
better to review commit-by-commit, and ignore `run black and isort`.
@jontwo
Copy link

jontwo commented Jun 22, 2023

We're still seeing this in v23.3.0. The --experimental-string-processing should have been removed by now, yes?

@JelleZijlstra
Copy link
Collaborator

It is not yet enabled by default; it's still part of --preview. Hopefully it will be the default in Black 24.

@tylerlaprade
Copy link

I have an f-string that looks like f"blah blah blah ... blah blah blah {my_variable}". This is getting auto-fixed when using --preview to

"blah blah blah ... blah blah blah"
f" {my_variable}"

which reports the violations reportImplicitStringConcatenation in Pyright and ISC002 in Ruff/Flake8.

@ichard26
Copy link
Collaborator

That's intentional. If you like this changed, please upvote/comment here: #2553.

sergiitk added a commit to grpc/psm-interop that referenced this issue Nov 8, 2023
- Switched  from yapf to black
- Reconfigure isort for black
- Resolve black/pylint idiosyncrasies 

Note: I used `--experimental-string-processing` because black was
producing "implicit string concatenation", similar to what described
here: psf/black#1837. While currently this
feature is experimental, it will be enabled by default:
psf/black#2188. After running black with the
new string processing so that the generated code merges these `"hello" "
world"` strings concatenations, then I removed
`--experimental-string-processing` for stability, and regenerated the
code again.

To the reviewer: don't even try to open "Files Changed" tab 😄 It's
better to review commit-by-commit, and ignore `run black and isort`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants