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

Black is not enforcing E: 501 #1582

Closed
kunal5 opened this issue Aug 11, 2020 · 6 comments
Closed

Black is not enforcing E: 501 #1582

kunal5 opened this issue Aug 11, 2020 · 6 comments
Labels
R: duplicate This issue or pull request already exists T: bug Something isn't working

Comments

@kunal5
Copy link

kunal5 commented Aug 11, 2020

Below is my pyproject.toml file

[tool.black]
target-version = ['py27']
line-length = 120
include = '\.pyi?$'
exclude = '''
(
  /(
      \.eggs         # exclude a few common directories in the
    | \.git          # root of the project
    | \.hg
    | \.mypy_cache
    | \.tox
    | \.venv
    | _build
    | buck-out
    | build
    | dist
    | migrations
  )/
  | foo.py           # also separately exclude a file named foo.py in
                     # the root of the project
  | apps/core/migrations/0002_auto_20200707_1828.py
)
'''

Below is my .flake8 file

[flake8]
max-line-length = 120

I have attached a screenshot of a dict in python
Screenshot 2020-08-11 at 2 11 28 PM

In the above image, line no 319 the line-length has exceeded the max length(120) given in the file. Black is not formatting this and flake8 is throwing error every time. Why is black not enforcing E: 501?
You can see this in the error snapshot
Screenshot 2020-08-11 at 2 16 53 PM

Black version is : 19.10b0
Python: 2.7

Please help!!
Thanks

@kunal5 kunal5 added the T: style What do we want Blackened code to look like? label Aug 11, 2020
@hugovk
Copy link
Contributor

hugovk commented Aug 11, 2020

What does that line 318 look like? Does it have a long string? Might be that Black couldn't make that line fit and you'll need to manually adjust it.

@kunal5
Copy link
Author

kunal5 commented Aug 11, 2020

@hugovk Please look at line 319... error message is showing line 318 because I deleted one line before taking a snapshot. Also, if I am placing the rest of the sentence after : in the next line then the black formatter is again formatting it and placing it on the same line

@hugovk
Copy link
Contributor

hugovk commented Aug 11, 2020

Ah right! One idea is to append # noqa: E501 to the line:

thing = {
    a: a,
    looooooooooooooooooooooooooooooooooooooooooooooooooooong: looooooooooooooooooooooooooooooooooooooooooooooooooooong,  # noqa: E501
}

@kunal5
Copy link
Author

kunal5 commented Aug 11, 2020

@hugovk what I am currently doing is appending fmt: off and fmt: on between the lines which I don't want black to format. But is there a way that black always respect line-length property as given in pyproject.toml ? There are many instances in my project when black is formatting a file but it is not respecting line-length=120 property. One more instance is
Ideal solution should be as given below in line 6001-6002
Screenshot 2020-08-11 at 3 21 00 PM
But, when I run black formatter, it is formatting the above file as given in line 6001-6002 which is again not respecting line-length property
Screenshot 2020-08-11 at 3 23 42 PM

This is happening at many places and I would not want to append fmt: off and fmt: on everywhere. Can I do anything different to fix this issue

@JelleZijlstra
Copy link
Collaborator

There are indeed certain patterns where Black is not able to fit lines in the desired line length, usually involving unreasonably long identifiers. We should fix such cases so that Black does obey the desired line length limit.

#620 and #510 are similar previous issues.

@ichard26 ichard26 added T: bug Something isn't working and removed T: style What do we want Blackened code to look like? labels Sep 16, 2020
@JelleZijlstra
Copy link
Collaborator

Going to call this a duplicate of #620.

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

No branches or pull requests

4 participants