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

Long string remains unchanged #1787

Closed
lyz-code opened this issue Oct 26, 2020 · 9 comments
Closed

Long string remains unchanged #1787

lyz-code opened this issue Oct 26, 2020 · 9 comments
Labels
R: not a bug This is deliberate behavior of Black.

Comments

@lyz-code
Copy link

lyz-code commented Oct 26, 2020

Long strings remain unchanged.

To Reproduce Steps to reproduce the behavior:

  1. Take this file:
value = "aldkfdskdksfjdskfj dslkfj sdkl dklsfj dsklfj sdklfjdsklfjdskl fjdskl jdsklf jdsklfj dsklfj dsklfj dsklfj dsklfj dsklfj dsklfj dkl"

fstring = f"f-strings definitely make things more {difficult} than they need to be for {{black}}. But boy they sure are handy. The problem is that some lines will need to have the 'f' whereas others do not. This {line}, for example, needs one."

good_split_func(
    xxx, yyy, zzz,
    long_string_kwarg="But what should happen when code has already "
                      "been formatted but in the wrong way? Like "
                      "with a space at the end instead of the "
                      "beginning. Or what about when it is split too "
                      "soon?",
)
  1. Run Black on it with no arguments.
  2. Actual output
value = "aldkfdskdksfjdskfj dslkfj sdkl dklsfj dsklfj sdklfjdsklfjdskl fjdskl jdsklf jdsklfj dsklfj dsklfj dsklfj dsklfj dsklfj dsklfj dkl"

fstring = f"f-strings definitely make things more {difficult} than they need to be for {{black}}. But boy they sure are handy. The problem is that some lines will need to have the 'f' whereas others do not. This {line}, for example, needs one."

good_split_func(
    xxx,
    yyy,
    zzz,
    long_string_kwarg="But what should happen when code has already "
    "been formatted but in the wrong way? Like "
    "with a space at the end instead of the "
    "beginning. Or what about when it is split too "
    "soon?",
)

Expected behavior: Formatting should meet the behaviour of #1132 .

Environment (please complete the following information):

  • Version: master (pip install git+git://github.com/psf/black)
  • OS and Python version: Linux/Python 3.7.3

Does this bug also happen on master? Yes, tested with black.now.sh

Additional context: After reviewing the git log, I've seen that the #1132 PR was merged into the branch origin/poetry but not into the current master. Although the code seems to be present

@lyz-code lyz-code added the T: bug Something isn't working label Oct 26, 2020
@hugovk
Copy link
Contributor

hugovk commented Oct 26, 2020

#1132 was disabled in #1609.

You can re-enable it with the undocumented --experimental-string-processing flag.

@lyz-code
Copy link
Author

Thanks @hugovk, it worked. Should I create a PR on the documentation to add this option?

@hugovk
Copy link
Contributor

hugovk commented Oct 26, 2020

Good to hear!

Nope, it's intentionally undocumented until the related crashes are fixed, and then it'll become the default when it's more stable. But thanks for the offer!

@ichard26 ichard26 added R: not a bug This is deliberate behavior of Black. and removed T: bug Something isn't working labels Oct 26, 2020
@ichard26
Copy link
Collaborator

Nope, it's intentionally undocumented until the related crashes are fixed, and then it'll become the default when it's more stable. But thanks for the offer!

Just to be clear, if we can't get the extra string processing stable enough it won't ever be released. On the flip side, that's unlikely as there already has been efforts by bbugyi200!

Closing as there isn't anything actionable in this issue.

@ghost
Copy link

ghost commented Oct 28, 2020

It doesn't work on the string
XCLIENT_ID = "123ij12o3i1j2o3icj12o3icj123ij12o3i1j2o3icj12o3icj123ij12o3i1j2o3icj12o3icj123ij12o3i1j2o3icj12o3icj123ij12o3i1j2o3icj12o3icj" using the --experimental-string-processing
@hugovk should I open a new issue?

@ichard26
Copy link
Collaborator

@asgmeonerandom the string is left unchanged because there isn't anything for Black to split on (i.e. no spaces).

It should be noted that #1132 will not change the output of the example that you gave above since the example string has no spaces in it. This would be undesirable, for example, in the case of long URLs.

#1331 (comment)

@ghost
Copy link

ghost commented Oct 30, 2020

@asgmeonerandom the string is left unchanged because there isn't anything for Black to split on (i.e. no spaces).

It should be noted that #1132 will not change the output of the example that you gave above since the example string has no spaces in it. This would be undesirable, for example, in the case of long URLs.

#1331 (comment)

mine has spaces between variables

@lyz-code
Copy link
Author

Is there any way of setting this setting in the pyproject.toml section? I've tried

[tool.black]
experimental_string_processing = true
experimental-string-processing = true
experimental_string_processing = "true"
experimental-string-processing = "true"

but none worked.

Thanks

@ichard26
Copy link
Collaborator

@lyz-code, the experimental_string_processing = true form should work, chances are that Black can't find your pyproject.toml file. When you run Black with verbose mode turned on (pass -v to it), Black will print a blue message that indicates it found and is using a configuration file (e.g. Using configuration from /home/ichard26/programming/oss/black/pyproject.toml.). Do you get that line, what is your directory structure, and how are you running Black?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R: not a bug This is deliberate behavior of Black.
Projects
None yet
Development

No branches or pull requests

3 participants