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 and isort incompatibility within stub files #837

Closed
gaborbernat opened this issue May 7, 2019 · 10 comments
Closed

black and isort incompatibility within stub files #837

gaborbernat opened this issue May 7, 2019 · 10 comments
Labels
T: bug Something isn't working

Comments

@gaborbernat
Copy link
Contributor

from tokenize import TokenInfo
from typing import Iterator, List

def replacetokens(tokens: List[TokenInfo], fullname: str) -> Iterator[TokenInfo]: ...
def apply_job_security(code: str) -> str: ...

In this case, black wants to put one line, while isort enforces two.

@JelleZijlstra JelleZijlstra added the T: bug Something isn't working label May 7, 2019
@gaborbernat
Copy link
Contributor Author

gaborbernat commented May 7, 2019

Workaround for now:

from tokenize import TokenInfo
from typing import Iterator, List

# needed to bypass https://github.com/python/black/issues/837

def replacetokens(tokens: List[TokenInfo], fullname: str) -> Iterator[TokenInfo]: ...
def apply_job_security(code: str) -> str: ...

@JelleZijlstra
Copy link
Collaborator

This is probably fixable with a special case in EmptyLineTracker._maybe_empty_lines that adds two newlines between imports and def lines even in stub files, but honestly I'd rather implement import sorting in Black itself.

@timothycrosley
Copy link

This is fully configurable in isort, however, isn't isort correct here according to pep8?

In fact, isn't black being self inconsistent, for example black produces this:

from tokenize import TokenInfo
from typing import Iterator, List


def function():
    pass

Adding the extra line if I remove it.
On what basis is black deciding to only use one line above?

@JelleZijlstra
Copy link
Collaborator

This is specifically in stub files (.pyi), which use a different, more compact coding style.

@timothycrosley
Copy link

@JelleZijlstra this makes sense, is this the standard for pyi files (the lack of the new line), is there an equivalent to pep8 for these files?

@JelleZijlstra
Copy link
Collaborator

The closest equivalent is the typeshed coding style: https://github.com/python/typeshed/blob/master/CONTRIBUTING.md#stub-file-coding-style.

@timothycrosley
Copy link

@JelleZijlstra thank you! With the additional information, I don't think this is an issue within Black. I'll have a resolution in isort shortly.

~Timothy

@JelleZijlstra
Copy link
Collaborator

Thank you!

@timothycrosley
Copy link

With version 4.3.19 isort has implemented black's behaviour for stub files

@gaborbernat
Copy link
Contributor Author

I'll close this then as it stands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants