Skip to content

MLC119: Scene.replace(old, new) with old definitely not in the scene

qual reports MLC119 when the old argument of self.replace(old, new) is provably outside the scene family at the call point. Scene.replace requires old to be present — directly or inside a parent — and raises ValueError otherwise (scene.py Scene.replace).

  • Default severity: error
  • Minimum confidence: high
  • Implementation phase: 2
  • Fix: none

Two proofs fire: old is a freshly constructed mobject (self.replace(Square(), new)), or every tracked possible referent of the old name is definitely absent from the scene family in the pre-call state. Presence through a parent group, branch-dependent (Maybe) membership, and unresolved values all stay silent.

Wrong

class Demo(Scene):
    def construct(self):
        old = Square()
        self.replace(old, Circle())  # old was never added
class Demo(Scene):
    def construct(self):
        old = Square()
        self.add(old)
        self.replace(old, Circle())