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 assert and parenthesized % format #1597

Closed
JelleZijlstra opened this issue Aug 13, 2020 · 4 comments · Fixed by #1681
Closed

Crash on assert and parenthesized % format #1597

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

Comments

@JelleZijlstra
Copy link
Collaborator

$ cat author.py 
class xxxxxxxxxxxxxxxxxxxxx(xxxx.xxxxxxxxxxxxx):
    def xxxxxxx_xxxxxx(xxxx):
        assert xxxxxxx_xxxx in [
            x.xxxxx.xxxxxx.xxxxx.xxxxxx,
            x.xxxxx.xxxxxx.xxxxx.xxxx,
        ], ("xxxxxxxxxxx xxxxxxx xxxx (xxxxxx xxxx) %x xxx xxxxx" % xxxxxxx_xxxx)
$ black -v author.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 912, in format_file_contents
    dst_contents = format_str(src_contents, 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 3315, in do_transform
    append_leaves(new_line, line, LL[: string_idx - 1])
  File "/Users/jelle/py/black/src/black/__init__.py", line 4601, in append_leaves
    new_line.append(new_leaf)
  File "/Users/jelle/py/black/src/black/__init__.py", line 1425, in append
    self.bracket_tracker.mark(leaf)
  File "/Users/jelle/py/black/src/black/__init__.py", line 1291, in mark
    opening_bracket = self.bracket_match.pop((self.depth, leaf.type))
KeyError: (-1, 10)
error: cannot format author.py: (-1, 10)
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

A third git bisect pointing to 544ea9c from PR #1132 "Improve String Handling".

@JelleZijlstra
Copy link
Collaborator Author

#1605 has another example of what's probably the same underlying bug. (I saw what looked like the same crash on several other files in my codebase too, but didn't try to minify the failures.)

@hugovk
Copy link
Contributor

hugovk commented Aug 21, 2020

This file now formats without errors with master.

$ black --version
black, version 19.10b1.dev154+gcd3a93a
$ black --check author.py
All done! ✨ 🍰 ✨
1 file would be left unchanged.

@bbugyi200
Copy link
Contributor

I was not able to replicate this on master with or without the --experimental-string-processing option. With that said, I included a test case for it in #1681 just in case.

I was, however, able to replicate #1605. This was fixed in #1681 and a corresponding test case was added to black's regression tests.

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

Successfully merging a pull request may close this issue.

3 participants