-
-
Notifications
You must be signed in to change notification settings - Fork 580
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
Regression: isort enforces two newlines after imports in pyi stub file. #1284
Comments
I have a similar issue which seems related. isort 5.0+ wants 2 blank lines between a from import within a def and a following comment. E.g.
is acceptable, but 0 or 1 blank lines between the This is not an issue if the first non-blank line following the import is not a comment. In that case, isort is happy with 0 or 1 blank lines. Update: I just looked at b228c37 and it seems my issue is probably not related, so I'll open a new one. |
Thank you for reporting! Thanks! ~Timothy |
This new version no longer has the problem of adding/removing a blank line in `.pyi` files, which black disagrees with. This would cause `isort` to slightly modify `.pyi` files, before `black` would subsequently modify back directly afterwards. Relevant `isort` issue: PyCQA/isort#1284
Unfortunately, this issue still persists when the extension is not known, i.e. when the file is passed from the stdin ( |
Hi @lukaszmoroz, isort provides a way to pass along both the file name or just the extension when passing streaming content via the command line. See: https://pycqa.github.io/isort/docs/configuration/options.html#ext-format and https://pycqa.github.io/isort/docs/configuration/options.html#filename |
Hi @timothycrosley -- we're still seeing this issue in Poetry when invoking isort with pre-commit. isort will incorrectly add two blank lines after imports in |
Hi @neersighted! Sorry to see you are experiencing this issue. If you are talking about poetry itself, it is because the project has the lines_after_imports setting hard coded to 2 in it's config: https://github.com/python-poetry/poetry/blob/master/pyproject.toml#L79 As an aside, it is also currently pinned to an older version of isort in the precommit: https://github.com/python-poetry/poetry/blob/master/.pre-commit-config.yaml#L26 You could set up pre-commit to have a different config for pyi files than py files or remove the config line length override entirely to fix. Let me know if I can help in any way. ~Timothy |
Hey @timothycrosley, thanks for replying so soon. Given your reply, would I be correct in assuming that this represents the correct solution? i.e. use a command line argument to override our configured two lines after imports, only for Thanks! |
@neersighted, yes! That is probably the best for now, there's an improvement here for isort to make to enable changing certain config options based on extension. Right now all config options are shared per a run of isort, and this setting in particular is either automatically handled (in which case it does automatically handle pyi files correctly) or is statically set, in which case isort applies it the same to every extension. |
Okay, it makes sense now, thanks! Some sort of localized override (filetype, file extension, path, etc) in pyproject.toml seems like the ultimate solution. Until then, we'll just reset it back to default. |
I think this is a regression of #942 in version 5.0.4, where black and isort disagree about the number of newlines after imports in a .pyi stub file:
isort wants to change this to:
My understanding from psf/black#837 and https://github.com/python/typeshed/blob/master/CONTRIBUTING.md#stub-file-coding-style is that black is correct here?
isort settings:
The text was updated successfully, but these errors were encountered: