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

Fix application of multiple suggested changes per file #449

Merged
merged 5 commits into from
Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Fix application of multiple suggested changes per file
when an earlier change has added or removed lines (#449)
- Treat `NoReturn` like `Any` in `**kwargs` calls (#446)
- Improve error messages for overloaded calls (#445)
- Infer `NoReturn` instead of `Any` for unreachable code (#443)
Expand Down
6 changes: 4 additions & 2 deletions pyanalyze/node_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ def _run_and_apply_changes(
else:
patches = []
for filename in changes:
offset = 0
for change in changes[filename]:
linenos = sorted(change.linenos_to_delete)
additions = change.lines_to_add
Expand All @@ -483,13 +484,14 @@ def _run_and_apply_changes(
start_lineno, end_lineno = linenos[0], linenos[0]
patches.append(
_PatchWithDescription(
start_lineno - 1,
end_lineno,
start_lineno - 1 + offset,
end_lineno + offset,
new_lines=additions,
path=filename,
description=change.error_str,
)
)
offset += len(additions or []) - len(linenos)
if patches:
# poor man's version of https://github.com/facebook/codemod/pull/113
with qcore.override(builtins, "print", _flushing_print):
Expand Down