Skip to content

Commit

Permalink
[AddImportsVisitor] generate deterministic add import output by sorti…
Browse files Browse the repository at this point in the history
…ng the sets.
  • Loading branch information
jimmylai committed Mar 25, 2020
1 parent 1b9a52b commit 67f7d66
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions libcst/codemod/visitors/_add_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,20 @@ def leave_ImportFrom(

# Now, do the actual update.
return updated_node.with_changes(
names=(
*[libcst.ImportAlias(name=libcst.Name(imp)) for imp in imports_to_add],
*[
names=[
*(
libcst.ImportAlias(name=libcst.Name(imp))
for imp in sorted(imports_to_add)
),
*(
libcst.ImportAlias(
name=libcst.Name(imp),
asname=libcst.AsName(name=libcst.Name(alias)),
)
for (imp, alias) in aliases_to_add
],
for (imp, alias) in sorted(aliases_to_add)
),
*updated_node.names,
)
]
)

def _split_module(
Expand Down

0 comments on commit 67f7d66

Please sign in to comment.