-
Notifications
You must be signed in to change notification settings - Fork 20
Handle missing nested packages in package_is_available - #76
Conversation
nhairs
commented
Sep 5, 2026
Hi @Sanjays2402
Can you give an example of why we need this?
Sanjays2402
commented
Sep 10, 2026
Sure — the concrete case is the msgspec extra: package_is_available("msgspec.structs") calls find_spec("msgspec.structs"), which raises ModuleNotFoundError (it doesn't return None) when the parent msgspec isn't installed, so without this patch the check blows up instead of reporting the extra as missing. Same for any dotted extra whose parent is absent. The patch only swallows the error when the missing module is the probed dependency itself — unrelated import errors from an existing parent (like a broken __init__) still propagate, covered by test_missing_dependency_in_parent_is_not_hidden.
nhairs
commented
Sep 12, 2026
Thanks
I'm still not convinced that this change is required. The function is very clearly scoped to packages rather than modules, it's only use within python-json-logger is with packages, and it is for internal use rather than external consumption.
Without a valid reason I'm inclined to close this pull request.
importlib.util.find_spec raises ModuleNotFoundError for missing parents in dotted module names. Treat missing modules in the requested name as unavailable while preserving unrelated dependency errors.