From 7bdaaa25c14f1572a2bc7083d73bc43c8d19c9f4 Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Sat, 5 Apr 2025 18:06:30 +0200 Subject: [PATCH] Core: Prevent worlds from using LogicMixin incorrectly (having class variables without an init_mixin) (#3974) * Core: Prevent people from using LogicMixin incorrectly There's a world that ran into some issues because it defined its custom LogicMixin variables at the class level. This caused "instance bleed" when new CollectionState objects were created. I don't think there is ever a reason to have a non-function class variable on LogicMixin without also having `init_mixin`, so this asserts that this is the case. Tested: Doesn't fail any current worlds Correctly fails the world in question Also, not gonna call out that world because it was literally my fault for explaining it to them wrong :D * Verbose af * Update AutoWorld.py --- worlds/AutoWorld.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/worlds/AutoWorld.py b/worlds/AutoWorld.py index 0fcacc8a..d1f4a772 100644 --- a/worlds/AutoWorld.py +++ b/worlds/AutoWorld.py @@ -110,6 +110,16 @@ class AutoLogicRegister(type): elif not item_name.startswith("__"): if hasattr(CollectionState, item_name): raise Exception(f"Name conflict on Logic Mixin {name} trying to overwrite {item_name}") + + assert callable(function) or "init_mixin" in dct, ( + f"{name} defined class variable {item_name} without also having init_mixin.\n\n" + "Explanation:\n" + "Class variables that will be mutated need to be inintialized as instance variables in init_mixin.\n" + "If your LogicMixin variables aren't actually mutable / you don't intend to mutate them, " + "there is no point in using LogixMixin.\n" + "LogicMixin exists to track custom state variables that change when items are collected/removed." + ) + setattr(CollectionState, item_name, function) return new_class