Skip to content

Commit

Permalink
Improved API consistency, returning a boolean value for all modificat…
Browse files Browse the repository at this point in the history
…ion API calls to indicate if changes were made.
  • Loading branch information
timothycrosley committed Aug 5, 2020
1 parent 86e33e7 commit 79bad69
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ NOTE: isort follows the [semver](https://semver.org/) versioning standard.
- Improved handling of deprecated single line variables for usage with Visual Studio Code (issue #1363)
- Improved handling of mixed newline forms within same source file.
- Improved error handling for known sections.
- Improved API consistency, returning a boolean value for all modification API calls to indicate if changes were made.
- Fixed #1366: spurious errors when combining skip with --gitignore.
- Fixed #1359: --skip-gitignore does not honor ignored symlink

Expand Down
11 changes: 7 additions & 4 deletions isort/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def sort_stream(
disregard_skip: bool = False,
show_diff: Union[bool, TextIO] = False,
**config_kwargs,
):
) -> bool:
"""Sorts any imports within the provided code stream, outputs to the provided output stream.
Directly returns nothing.
Returns `True` if anything is modified from the original input stream, otherwise `False`.
- **input_stream**: The stream of code with imports that need to be sorted.
- **output_stream**: The stream where sorted imports should be written to.
Expand Down Expand Up @@ -280,8 +280,9 @@ def sort_file(
show_diff: Union[bool, TextIO] = False,
write_to_stdout: bool = False,
**config_kwargs,
):
) -> bool:
"""Sorts and formats any groups of imports imports within the provided file or Path.
Returns `True` if the file has been changed, otherwise `False`.
- **filename**: The name or Path of the file to format.
- **extension**: The file extension that contains imports. Defaults to filename extension or py.
Expand Down Expand Up @@ -341,7 +342,7 @@ def sort_file(
str(source_file.path)
)
):
return
return False
source_file.stream.close()
tmp_file.replace(source_file.path)
if not config.quiet:
Expand All @@ -356,6 +357,8 @@ def sort_file(
except IntroducedSyntaxErrors: # pragma: no cover
warn(f"{file_path} unable to sort as isort introduces new syntax errors")

return changed


def _config(
path: Optional[Path] = None, config: Config = DEFAULT_CONFIG, **config_kwargs
Expand Down

0 comments on commit 79bad69

Please sign in to comment.