From 92ca11b72925a83e0c18e10bb4f66edd5d6402ec Mon Sep 17 00:00:00 2001 From: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com> Date: Sat, 21 Sep 2024 18:02:24 +0200 Subject: [PATCH] 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 --- worlds/AutoWorld.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/worlds/AutoWorld.py b/worlds/AutoWorld.py index 19ec9a14a8..067bf30403 100644 --- a/worlds/AutoWorld.py +++ b/worlds/AutoWorld.py @@ -107,6 +107,11 @@ 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." + ) + setattr(CollectionState, item_name, function) return new_class