From bc8de1245d844274e88c3578aab6136c83de021f Mon Sep 17 00:00:00 2001 From: Michael Cahill Date: Sat, 7 Mar 2026 21:23:35 -0800 Subject: [PATCH] ci(M01): use module-level cache for UPPER_CASE dict stubs Made-with: Cursor --- scripts/dev/create_stub_repos.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/dev/create_stub_repos.py b/scripts/dev/create_stub_repos.py index a8230a7d5..0d3e08235 100644 --- a/scripts/dev/create_stub_repos.py +++ b/scripts/dev/create_stub_repos.py @@ -40,6 +40,8 @@ def _make_stub_class(name): return _noop return _Meta(name, (), {"forward": _noop}) +_const_cache = {} # id(module) -> {attr: dict} for UPPER_CASE + class _StubModule(types.ModuleType): """Resolves any attribute as submodule or stub class.""" @@ -49,10 +51,10 @@ class _StubModule(types.ModuleType): if name and name[0].isupper(): # UPPER_CASE on module -> dict (e.g. midas.api.ISL_PATHS) if "_" in name or name.isupper(): - cache = getattr(self, "_d", None) - if cache is None: - cache = {} - object.__setattr__(self, "_d", cache) + cid = id(self) + if cid not in _const_cache: + _const_cache[cid] = {} + cache = _const_cache[cid] if name not in cache: cache[name] = {} return cache[name]