WIP: Add copying where it might be necessary #4122
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NOTE: This is not ready for review, I have a significant amount of documentation to add, I need to update the test suite, and I missed several cases that I am writing out below. I am posting this early to receive feedback on the broad strokes of the approach, the implementation is (right now) entirely incorrect.
NOTE: a re-open of #4118, but with best practices observed!
Description
A proposed fix for #4113 that identifies what parameters might be mutated within a function that Ghostwriter is called on. To prevent side effects (particularly in equivalence mode), adds a call to
copy.deepcopy
to the parameter in the test function.Right now, I mark a variable as potentially modified if:
ast.Assign
orast.AugAssign
that is not inside anast.Subscript
orast.Slice
. This includes when it is being indexed into or an attribute of it is being assignedCall
ed. Even if this isn't on the left-hand side of an assignment, it is safe to assume that any call may create side effects.Todo
value
ofast.Subscript
orslice
inast.Slice
potentially_modified_vars