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

Crash on concatenated string + comment #1596

Closed
JelleZijlstra opened this issue Aug 13, 2020 · 3 comments
Closed

Crash on concatenated string + comment #1596

JelleZijlstra opened this issue Aug 13, 2020 · 3 comments
Labels
C: crash Black is crashing T: bug Something isn't working

Comments

@JelleZijlstra
Copy link
Collaborator

Another crash on master

$ cat xxx.py 
xxxxxxx_xxxxxx_xxxxxxx = xxx(
    [
        xxxxxxxxxxxx(
            xxxxxx_xxxxxxx=(
                '((x.xxxxxxxxx = "xxxxxx.xxxxxxxxxxxxxxxxxxxxx") || (x.xxxxxxxxx = "xxxxxxxxxxxx")) && '
                # xxxxx xxxxxxxxxxxx xxxx xxx (xxxxxxxxxxxxxxxx) xx x xxxxxxxxx xx xxxxxx.
                "(x.xxxxxxxxxxxx.xxx != "
                '"xxx:xxx:xxx::xxxxxxxxxxxx:xxxxxxx-xxxx/xxxxxxxxxxx/xxxxxxxxxxxxxxxxx") && '
            )
        )
    ]
)
$ black -v xxx.py 
Using configuration from /Users/jelle/py/black/pyproject.toml.
Traceback (most recent call last):
  File "/Users/jelle/py/black/src/black/__init__.py", line 648, in reformat_one
    if changed is not Changed.CACHED and format_file_in_place(
  File "/Users/jelle/py/black/src/black/__init__.py", line 791, in format_file_in_place
    dst_contents = format_file_contents(src_contents, fast=fast, mode=mode)
  File "/Users/jelle/py/black/src/black/__init__.py", line 918, in format_file_contents
    assert_stable(src_contents, dst_contents, mode=mode)
  File "/Users/jelle/py/black/src/black/__init__.py", line 6076, in assert_stable
    newdst = format_str(dst, mode=mode)
  File "/Users/jelle/py/black/src/black/__init__.py", line 977, in format_str
    for line in transform_line(
  File "/Users/jelle/py/black/src/black/__init__.py", line 2731, in transform_line
    result.extend(
  File "/Users/jelle/py/black/src/black/__init__.py", line 2725, in transform_line
    for transformed_line in transform(line, features):
  File "/Users/jelle/py/black/src/black/__init__.py", line 2834, in __call__
    for line_result in self.do_transform(line, string_idx):
  File "/Users/jelle/py/black/src/black/__init__.py", line 2978, in do_transform
    msg_result = self.__merge_string_group(new_line, string_idx)
  File "/Users/jelle/py/black/src/black/__init__.py", line 3164, in __merge_string_group
    new_line.append(string_leaf)
  File "/Users/jelle/py/black/src/black/__init__.py", line 1421, in append
    leaf.prefix += whitespace(
  File "/Users/jelle/py/black/src/black/__init__.py", line 2152, in whitespace
    assert p is not None, f"INTERNAL ERROR: hand-made leaf without parent: {leaf!r}"
AssertionError: INTERNAL ERROR: hand-made leaf without parent: Leaf(STRING, '\'(x.xxxxxxxxxxxx.xxx != "xxx:xxx:xxx::xxxxxxxxxxxx:xxxxxxx-xxxx/xxxxxxxxxxx/xxxxxxxxxxxxxxxxx") && \'')
error: cannot format xxx.py: INTERNAL ERROR: hand-made leaf without parent: Leaf(STRING, '\'(x.xxxxxxxxxxxx.xxx != "xxx:xxx:xxx::xxxxxxxxxxxx:xxxxxxx-xxxx/xxxxxxxxxxx/xxxxxxxxxxxxxxxxx") && \'')
Oh no! 💥 💔 💥
1 file failed to reformat.
@JelleZijlstra JelleZijlstra added T: bug Something isn't working C: crash Black is crashing labels Aug 13, 2020
@hugovk
Copy link
Contributor

hugovk commented Aug 13, 2020

git bisect also points to 544ea9c as the first bad commit, from PR #1132 "Improve String Handling".

@hugovk
Copy link
Contributor

hugovk commented Aug 21, 2020

Now fine on master

$ black --check xxx.py
All done! ✨ 🍰 ✨
1 file would be left unchanged.

@JelleZijlstra
Copy link
Collaborator Author

Yes, #1609 disables the feature that caused the crash. I left the issue open because we need to fix it in order to get rid of the experimental flag.

bbugyi200 added a commit to bbugyi200/black that referenced this issue Sep 5, 2020
noxan pushed a commit to noxan/black that referenced this issue Jun 6, 2021
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: crash Black is crashing T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants