Skip to content

Commit 7e212c0

Browse files
committed
Flip for loop order in metaprogramming.py
1 parent 264240e commit 7e212c0

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

sqlmesh/utils/metaprogramming.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,11 @@ def _resolve_import_module(obj: t.Any, name: str) -> str:
463463
module_name = getattr(obj, "__module__", None) or ""
464464
parts = module_name.split(".")
465465

466-
# Walk from the immediate parent up to (but not including) the top-level
467-
# package, stopping at the first ancestor that also exports the object.
468-
# We stop before the top-level package to avoid over-normalizing
469-
# (e.g. ``sqlglot`` re-exports everything, but callers expect the more
470-
# specific ``sqlglot.expressions`` when that is where the object lives).
471-
for i in range(len(parts) - 1, 1, -1):
466+
# Walk from the shallowest ancestor (excluding the top-level package) up to
467+
# the immediate parent, returning the shallowest one that re-exports the object.
468+
# We skip the top-level package to avoid over-normalizing (e.g. ``sqlglot``
469+
# re-exports everything, but callers expect ``sqlglot.expressions``).
470+
for i in range(2, len(parts)):
472471
parent = ".".join(parts[:i])
473472
try:
474473
parent_module = sys.modules.get(parent) or importlib.import_module(parent)

0 commit comments

Comments
 (0)