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

error: cannot format Tests/test_file_libtiff.py: (-1, 8) #1605

Closed
hugovk opened this issue Aug 14, 2020 · 5 comments · Fixed by #1681
Closed

error: cannot format Tests/test_file_libtiff.py: (-1, 8) #1605

hugovk opened this issue Aug 14, 2020 · 5 comments · Fixed by #1681
Labels
C: crash Black is crashing R: duplicate This issue or pull request already exists T: bug Something isn't working

Comments

@hugovk
Copy link
Contributor

hugovk commented Aug 14, 2020

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Take this file https://github.com/python-pillow/Pillow/blob/e54909b97c213278accc8176f1c52e403f8afcb6/Tests/test_file_libtiff.py
  2. Run Black on it with these arguments --check Tests/test_file_libtiff.py
  3. See error
$ black --version
black, version 19.10b1.dev141+g820f387
$ black --check Tests/test_file_libtiff.py
error: cannot format Tests/test_file_libtiff.py: (-1, 8)
Oh no! 💥 💔 💥
1 file would fail to reformat.

Expected behavior A clear and concise description of what you expected to happen.

File formats.

Environment (please complete the following information):

  • Version: master
  • OS and Python version: macOS/Python 3.8.3

Does this bug also happen on master? To answer this, you have two options:

Yes, see above.

Works with last release (the codebase is already formatted with that version):

$ black --version
black, version 19.10b0
$ black --check Tests/test_file_libtiff.py
All done! ✨ 🍰 ✨
1 file would be left unchanged.

Additional context Add any other context about the problem here.

Looks like it's this part:

                            assert (
                                c_float(val[0][0] / val[0][1]).value
                                == c_float(value[0][0] / value[0][1]).value
                            ), ("%s didn't roundtrip" % tag)

https://github.com/python-pillow/Pillow/blob/e54909b97c213278accc8176f1c52e403f8afcb6/Tests/test_file_libtiff.py#L171-L174

(We're about to drop Python 3.5 and adopt f-strings, it's replacement is handled fine:

                            assert (
                                c_float(val[0][0] / val[0][1]).value
                                == c_float(value[0][0] / value[0][1]).value
                            ), f"{tag} didn't roundtrip"

)

@hugovk hugovk added the T: bug Something isn't working label Aug 14, 2020
@hugovk
Copy link
Contributor Author

hugovk commented Aug 14, 2020

git bisect -> 544ea9c in "Improve String Handling" (#1132)

Possibly duplicate of #1597?

@ichard26 ichard26 added the C: crash Black is crashing label Aug 14, 2020
@ichard26
Copy link
Collaborator

ichard26 commented Aug 14, 2020

Possibly duplicate of #1597?

Probably, but I don't trust myself to accurately know due to lack of familiarity with Black's formatting code so I'll someone else decide that.

FYI: Jelle created a PR (#1594) where in verbose mode, Black prints out the trackback on failure so it's a bit more clear that there was an IndexError KeyError 🙂.

@JelleZijlstra
Copy link
Collaborator

I'm pretty sure this is the same underlying issue as #1597, but when we fix it we should make sure both cases are covered. Closing this one as a duplicate though.

@ichard26 ichard26 added the R: duplicate This issue or pull request already exists label Aug 14, 2020
@hugovk
Copy link
Contributor Author

hugovk commented Aug 14, 2020

FYI: Jelle created a PR (#1594) where in verbose mode, Black prints out the trackback on failure so it's a bit more clear that there was an IndexError 🙂.

That's useful!

Same traceback:

Traceback (most recent call last):
  File "/Users/hugo/github/black/src/black/__init__.py", line 657, in reformat_one
    if changed is not Changed.CACHED and format_file_in_place(
  File "/Users/hugo/github/black/src/black/__init__.py", line 800, in format_file_in_place
    dst_contents = format_file_contents(src_contents, fast=fast, mode=mode)
  File "/Users/hugo/github/black/src/black/__init__.py", line 921, in format_file_contents
    dst_contents = format_str(src_contents, mode=mode)
  File "/Users/hugo/github/black/src/black/__init__.py", line 986, in format_str
    for line in transform_line(
  File "/Users/hugo/github/black/src/black/__init__.py", line 2740, in transform_line
    result.extend(
  File "/Users/hugo/github/black/src/black/__init__.py", line 2734, in transform_line
    for transformed_line in transform(line, features):
  File "/Users/hugo/github/black/src/black/__init__.py", line 2843, in __call__
    for line_result in self.do_transform(line, string_idx):
  File "/Users/hugo/github/black/src/black/__init__.py", line 3363, in do_transform
    append_leaves(new_line, line, LL[: string_idx - 1])
  File "/Users/hugo/github/black/src/black/__init__.py", line 4649, in append_leaves
    new_line.append(new_leaf)
  File "/Users/hugo/github/black/src/black/__init__.py", line 1434, in append
    self.bracket_tracker.mark(leaf)
  File "/Users/hugo/github/black/src/black/__init__.py", line 1300, in mark
    opening_bracket = self.bracket_match.pop((self.depth, leaf.type))
KeyError: (-1, 8)

@hugovk
Copy link
Contributor Author

hugovk commented Aug 21, 2020

This file now formats without errors with master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: crash Black is crashing R: duplicate This issue or pull request already exists T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants