Black: can't format python2 valid syntax

Created on 7 May 2018  路  2Comments  路  Source: psf/black

A fairly ugly open-source python2 file ends in "cannot format":

$ curl  https://raw.githubusercontent.com/atlas0fd00m/rfcat/master/rflib/bits.py > bits.py && \
 python2 bits.py && \
 black bits.py
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 20012  100 20012    0     0  20012      0  0:00:01 --:--:--  0:00:01  125k
error: cannot format /home/dcarlson/bits.py: (-1, 8)

Operating system: Fedora 27
Python version: 2.7.14-10.fc27 & 3.6.5-1.fc27.x86_64
Black version: black-18.4a4

Does also happen on master: yes (reported version 18.4a5)
(yes, I did the virtualenv stuff, a-ok)

bug

Most helpful comment

I was playing with this for a bit. This is a minimal failing example I got:

for aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa in range(1):  # aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    pass

Issue seems to be when attempting to right_hand_split this:

):  # aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

which has two right-parenthesis leafs and one of them ends up alone in the body which leads to bracket matching failure.

I don't have enough context to make a proper fix, but leaving it here to save some debugging time.

All 2 comments

Thanks for the report! Definitely a bug to be fixed soon.

I was playing with this for a bit. This is a minimal failing example I got:

for aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa in range(1):  # aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    pass

Issue seems to be when attempting to right_hand_split this:

):  # aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

which has two right-parenthesis leafs and one of them ends up alone in the body which leads to bracket matching failure.

I don't have enough context to make a proper fix, but leaving it here to save some debugging time.

Was this page helpful?
0 / 5 - 0 ratings