Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkgutil.find_loader() raises ImportError instead of returning None #65410

Closed
ericsnowcurrently opened this issue Apr 14, 2014 · 3 comments
Closed
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@ericsnowcurrently
Copy link
Member

BPO 21211
Nosy @brettcannon, @ncoghlan, @ericsnowcurrently

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2014-04-19.03:34:59.024>
created_at = <Date 2014-04-14.01:48:18.439>
labels = ['invalid', 'type-bug', 'library']
title = 'pkgutil.find_loader() raises ImportError instead of returning None'
updated_at = <Date 2014-04-19.03:34:59.023>
user = 'https://github.com/ericsnowcurrently'

bugs.python.org fields:

activity = <Date 2014-04-19.03:34:59.023>
actor = 'eric.snow'
assignee = 'none'
closed = True
closed_date = <Date 2014-04-19.03:34:59.024>
closer = 'eric.snow'
components = ['Library (Lib)']
creation = <Date 2014-04-14.01:48:18.439>
creator = 'eric.snow'
dependencies = []
files = []
hgrepos = []
issue_num = 21211
keywords = ['3.3regression']
message_count = 3.0
messages = ['216047', '216460', '216840']
nosy_count = 3.0
nosy_names = ['brett.cannon', 'ncoghlan', 'eric.snow']
pr_nums = []
priority = 'high'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue21211'
versions = ['Python 3.3', 'Python 3.4', 'Python 3.5']

@ericsnowcurrently
Copy link
Member Author

In 3987667bf98f pkgutil.find_loader() switched from using pkgutil.iter_importers() to importlib.find_module(). importlib.find_module() checks the module's __loader__ (and raises ImportError when invalid) whereas iter_importers() does no such check. In 3.4 pkgutil.find_loader() switched over to importlib.util.find_spec(), but the same issue remains.

The documentation (and the previous behavior) implies that the ImportError case coming out of find_spec() should result in pkgutil.find_loader() returning None rather than propagating the ImportError. However, it may make more sense to do an explicit check for module.__spec__ before calling find_spec().

@ericsnowcurrently ericsnowcurrently added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 14, 2014
@ericsnowcurrently
Copy link
Member Author

Ah, it's ValueError rather than ImportError that causes the problem. Regardless, handling it would be necessary.

@ericsnowcurrently
Copy link
Member Author

On second thought, all modules (except __main__) must have both __spec__ and __loader__ set to their correct respective objects. So the current behavior is correct in that it exposes poorly formed modules.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant