Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Commit e2ad3fb

Browse files
committed
Handle newer and older isort with respect to sorter.output
1 parent 8d2c9dd commit e2ad3fb

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

esss_fix_format/cli.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ def main(files_or_directories, check, stdin, commit):
9696
errors.append(error_msg)
9797

9898
sorter = isort.SortImports(file_contents=new_contents, settings_path=settings_path)
99-
# strangely, if the entire file is skipped by an "isort:skip_file"
100-
# instruction in the docstring, SortImports doesn't even contain an
101-
# "output" attribute
102-
if hasattr(sorter, 'output'):
103-
new_contents = sorter.output
99+
# On older versions if the entire file is skipped (eg.: by an "isort:skip_file")
100+
# instruction in the docstring, SortImports doesn't even contain an "output" attribute.
101+
# In some recent versions it is `None`.
102+
new_contents = getattr(sorter, 'output', None)
103+
if new_contents is None:
104+
new_contents = original_contents
104105

105106
new_contents = fix_whitespace(new_contents.splitlines(True), eol, ends_with_eol)
106107
changed = new_contents != original_contents

0 commit comments

Comments
 (0)