Skip to content

Commit 6144b53

Browse files
simplify catalog __init__.py imports
1 parent 5f8b79d commit 6144b53

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

src/pygambit/catalog/__init__.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
1-
from . import catalog
2-
from .catalog import games
1+
from .catalog import CatalogGame, games
32

4-
# Ensure catalog module is fully imported including all YAML-generated classes
5-
_all_catalog_classes = games()
6-
_all_catalog_classes.append("CatalogGame") # Ensure base class is included
3+
__all__ = ["games", "CatalogGame"]
74

8-
_game_classes = {}
95

10-
for game_name in _all_catalog_classes:
11-
try:
12-
_game_classes[game_name] = getattr(catalog, game_name)
13-
except AttributeError as e:
14-
raise ImportError(
15-
f"Catalog game '{game_name}' listed but not found in catalog module"
16-
) from e
17-
18-
# Add to module namespace
19-
globals().update(_game_classes)
20-
21-
# Build __all__ dynamically
22-
__all__ = ["games", *list(_all_catalog_classes)]
6+
def __getattr__(name: str):
7+
"""Lazy load catalog games on access."""
8+
from . import catalog as _catalog_module
9+
return getattr(_catalog_module, name)

0 commit comments

Comments
 (0)