Skip to content

Resolve lazy module exports in import_global - #66

Merged
wolph merged 1 commit into
wolph:developfrom
ShahadatTest:fix/import-global-lazy-exports
Oct 29, 2026
Merged

wolph merged 1 commit into
wolph:developfrom
ShahadatTest:fix/import-global-lazy-exports

Conversation

@ShahadatTest

Copy link
Copy Markdown
Contributor

import_global() silently drops exports supplied by a module's __getattr__ when those names are absent from dir(module). This happens even when the module declares them in __all__ or the caller explicitly requests them.

Resolve the selected names through getattr instead of intersecting them with dir(). Missing names and private names remain excluded, and a real exported None is retained. Tests exercise declared and explicit lazy exports and verify each value is resolved once. The parameter documentation explains this behavior.

Both new regressions fail before the fix. Full Python 3.10 and 3.12 suites: 371 passed, 5 optional timezone-data skips, 100% branch/statement coverage. Whole-project mypy, basedpyright and Pyrefly report no errors. Ruff lint and formatting of changed files, plus git diff --check, pass. No matching open issue or PR found.

AI assistance: OpenAI Codex (GPT-6). Original user request: new 14ta koro aro (make 14 more new contributions). Diff inspection was automated; no human review or personal production usage is claimed.

@wolph
wolph merged commit 1e1b03e into wolph:develop Oct 29, 2026
17 checks passed
wolph added a commit that referenced this pull request Oct 29, 2026
#66 resolves every requested name through getattr. A lazy export whose
__getattr__ raised, such as an optional dependency, made import_global
raise where 4.x skipped it, a name in modules or __all__ that is not a
str raised TypeError, and an explicit name on a module with a catch-all
__getattr__ was fetched from it. A name that dir() does not list is now
resolved only when __all__ declares it, and skipped when that fails.
@wolph

wolph commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Thanks for the fix :)

I've made a few changes on top (65e44b7). A lazy export that fails to resolve, such as an optional dependency that isn't installed, is skipped again instead of raising, and names that aren't strings are ignored as before. A name that dir() doesn't list is now only fetched when __all__ declares it, so a module with a catch-all __getattr__ isn't asked for every requested name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants