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

Change find_module to find_spec for py37 compat #1563

Merged
merged 7 commits into from
Mar 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/1563.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In ``pkg_resources`` prefer ``find_spec`` (PEP 451) to ``find_module``.
12 changes: 8 additions & 4 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2098,10 +2098,14 @@ def _handle_ns(packageName, path_item):
if importer is None:
return None

# capture warnings due to #1111
with warnings.catch_warnings():
warnings.simplefilter("ignore")
loader = importer.find_module(packageName)
# use find_spec (PEP 451) and fall-back to find_module (PEP 302)
try:
loader = importer.find_spec(packageName).loader
except AttributeError:
# capture warnings due to #1111
with warnings.catch_warnings():
warnings.simplefilter("ignore")
loader = importer.find_module(packageName)

if loader is None:
return None
Expand Down