Core: adds a custom KeyError for invalid item names (#4223)

* adds a custom KeyError for raising on world.create_item() if the passed in name is invalid

* Update __init__.py

---------

Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com>
This commit is contained in:
qwint
2025-09-08 04:11:46 -05:00
committed by GitHub
parent 1b200fb20b
commit 63f3512829
2 changed files with 6 additions and 2 deletions

View File

@@ -22,6 +22,10 @@ if TYPE_CHECKING:
perf_logger = logging.getLogger("performance")
class InvalidItemError(KeyError):
pass
class AutoWorldRegister(type):
world_types: Dict[str, Type[World]] = {}
__file__: str

View File

@@ -3,7 +3,7 @@ import logging
from BaseClasses import Item, Tutorial, ItemClassification
from ..AutoWorld import World, WebWorld
from ..AutoWorld import InvalidItemError, World, WebWorld
from NetUtils import SlotType
@@ -47,7 +47,7 @@ class GenericWorld(World):
def create_item(self, name: str) -> Item:
if name == "Nothing":
return Item(name, ItemClassification.filler, -1, self.player)
raise KeyError(name)
raise InvalidItemError(name)
class PlandoItem(NamedTuple):