Skip to content

Rule for copying mutable objects between two persistent variables #21688

@EternityForest

Description

@EternityForest

Summary

One bug pattern that I've encountered several times is
something like a.x = b.x, or even a.x = a.y = {}

The times I've done it are often when doing change detection, you do x.old = x.new, then mutate x.old, when you meant to do x.old = deepcopy(x.new)

Then, something mutates one of the two variables, and they both change, because they're the same object, and it can be very hard to track down why keys are suddenly appearing for seemingly no reason in your data structures.

Maybe there could be a rule that prevents assigning one mutable property of an object directly or indirectly(like by passing it as a an argument) to another.

It could also warn on assigning one mutable item to multiple objects, or assigning between globals and objects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-decisionAwaiting a decision from a maintainerruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions