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 compatibility: ignore lines_after_imports for .pyi typing stubs #1976

Closed
XuehaiPan opened this issue Oct 8, 2022 · 0 comments · Fixed by #2017
Closed

black compatibility: ignore lines_after_imports for .pyi typing stubs #1976

XuehaiPan opened this issue Oct 8, 2022 · 0 comments · Fixed by #2017

Comments

@XuehaiPan
Copy link
Contributor

isort and black are two famous quality control tools. And usually, they are used together. Black Compatibility

The user may set custom lines_after_imports in their configuration file (e.g. pyproject.toml):

[tool.black]
safe = true
line-length = 88
skip-string-normalization = true
target-version = ["py37", "py38", "py39", "py310"]

[tool.isort]
atomic = true
profile = "black"
indent = 4
line_length = 100
lines_after_imports = 2
multi_line_output = 3

For .py files, the maximum empty lines for black are 2 and everything works fine. However, for .pyi stubs files, black only allows a single blank line at the top level, while isort adds an extra blank line when setting lines_after_imports = 2.

https://github.com/psf/black/blob/b60b85b234d6a575f636d0a125478115f993c90c/src/black/lines.py#L485-L487

For .pyi files, if the user runs black first and then isort, there will be 2 empty lines after imports. If the user runs isort before black, there will be only 1 empty line after imports. Both black and isort will modify the .pyi files. And command:

isort --check *.pyi && black --check *.pyi

always fails if set lines_after_imports = 2.

The user have to add isort: off at the top of all .pyi files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant