diff options
author | Timothy Crosley <timothy.crosley@gmail.com> | 2019-12-19 20:52:25 -0800 |
---|---|---|
committer | Timothy Crosley <timothy.crosley@gmail.com> | 2019-12-19 20:52:25 -0800 |
commit | f5ef546ede9450b19d7c615ab7e7c833f88a7dcf (patch) | |
tree | 7f091ed9001143fb9280a110f65186379ec81bbb | |
parent | 1a78b0427517a3f8df34a32c502a0e75c3fe17e3 (diff) | |
download | isort-f5ef546ede9450b19d7c615ab7e7c833f88a7dcf.tar.gz |
Fix linting errors
-rw-r--r-- | isort/api.py | 1 | ||||
-rw-r--r-- | isort/output.py | 1 | ||||
-rw-r--r-- | isort/parse.py | 27 |
3 files changed, 7 insertions, 22 deletions
diff --git a/isort/api.py b/isort/api.py index 882e3cc8..30c9f0f3 100644 --- a/isort/api.py +++ b/isort/api.py @@ -146,6 +146,7 @@ def sort_imports( first_comment_index_end: int = -1 contains_imports: bool = False in_top_comment: bool = False + section_comments = [f"# {heading}" for heading in config.import_headings.values()] for index, line in enumerate(input_stream): if index == 1 and line.startswith("#"): in_top_comment = True diff --git a/isort/output.py b/isort/output.py index cf02e7b4..a6b4a7a9 100644 --- a/isort/output.py +++ b/isort/output.py @@ -163,7 +163,6 @@ def sorted_imports( should_skip, _in_quote, *_ = parse.skip_line( line, in_quote=_in_quote, - in_top_comment=False, index=len(formatted_output), section_comments=parsed.section_comments, ) diff --git a/isort/parse.py b/isort/parse.py index 96dd7d89..1b459119 100644 --- a/isort/parse.py +++ b/isort/parse.py @@ -77,10 +77,7 @@ def _strip_syntax(import_string: str) -> str: def skip_line( - line: str, - in_quote: str, - index: int, - section_comments: List[str], + line: str, in_quote: str, index: int, section_comments: List[str] ) -> Tuple[bool, str]: """Determine if a given line should be skipped. @@ -114,10 +111,7 @@ def skip_line( if part and not part.startswith("from ") and not part.startswith("import "): skip_line = True - return ( - bool(skip_line or in_quote), - in_quote - ) + return (bool(skip_line or in_quote), in_quote) class ParsedContent(NamedTuple): @@ -171,14 +165,8 @@ def file_contents(contents: str, config: Config = DEFAULT_CONFIG) -> ParsedConte line = in_lines[index] index += 1 statement_index = index - ( - skipping_line, - in_quote, - ) = skip_line( - line, - in_quote=in_quote, - index=index, - section_comments=section_comments, + (skipping_line, in_quote) = skip_line( + line, in_quote=in_quote, index=index, section_comments=section_comments ) if line in section_comments and not skipping_line: @@ -345,10 +333,7 @@ def file_contents(contents: str, config: Config = DEFAULT_CONFIG) -> ParsedConte categorized_comments["above"]["from"].setdefault(import_from, []).insert( 0, out_lines.pop(-1) ) - if ( - len(out_lines) - > max(import_index - 1, 1) - 1 - ): + if len(out_lines) > max(import_index - 1, 1) - 1: last = out_lines[-1].rstrip() else: last = "" @@ -372,7 +357,7 @@ def file_contents(contents: str, config: Config = DEFAULT_CONFIG) -> ParsedConte categorized_comments["straight"][module] = comments comments = [] - if len(out_lines) > max(import_index, + 1, 1) - 1: + if len(out_lines) > max(import_index, +1, 1) - 1: last = out_lines and out_lines[-1].rstrip() or "" while ( |