Skip to content

Handle missing nested packages in package_is_available - #76

Open
Sanjays2402 wants to merge 1 commit into
nhairs:mainfrom
Sanjays2402:fix/oss-contribution
Open

Handle missing nested packages in package_is_available#76
Sanjays2402 wants to merge 1 commit into
nhairs:mainfrom
Sanjays2402:fix/oss-contribution

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

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.

@nhairs

nhairs commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Hi @Sanjays2402

Can you give an example of why we need this?

@Sanjays2402

Copy link
Copy Markdown
Contributor Author

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

nhairs commented Sep 12, 2026

Copy link
Copy Markdown
Owner

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.

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