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

Fix deprecated importlib methods #869

Merged
merged 10 commits into from
Dec 30, 2020
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ What's New in astroid 2.5.0?
============================
Release Date: TBA

* Fix deprecated importlib methods

Closes #703

* Add `python 3.9` support.

Expand Down
17 changes: 16 additions & 1 deletion astroid/interpreter/_import/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Copyright (c) 2018 Nick Drozd <nicholasdrozd@gmail.com>
# Copyright (c) 2019 Hugo van Kemenade <hugovk@users.noreply.github.com>
# Copyright (c) 2019 Ashley Whetter <ashley@awhetter.co.uk>
# Copyright (c) 2020 Gergely Kalmar <GergelyKalmar@users.noreply.github.com>
# Copyright (c) 2020 Peter Kolbus <peter.kolbus@gmail.com>
# Copyright (c) 2020 Raphael Gaschignard <raphael@rtpg.co>

Expand Down Expand Up @@ -272,6 +273,16 @@ def _cached_set_diff(left, right):


def _precache_zipimporters(path=None):
"""
For each path that has not been already cached
in the sys.path_importer_cache, create a new zipimporter
instance and add it into the cache.
Return a dict associating all paths, stored in the cache, to corresponding
zipimporter instances.

:param path: paths that has to be added into the cache
:return: association between paths stored in the cache and zipimporter instances
"""
pic = sys.path_importer_cache

# When measured, despite having the same complexity (O(n)),
Expand All @@ -287,7 +298,11 @@ def _precache_zipimporters(path=None):
pic[entry_path] = zipimport.zipimporter(entry_path)
except zipimport.ZipImportError:
continue
return pic
return {
key: value
for key, value in pic.items()
if isinstance(value, zipimport.zipimporter)
}


def _search_zip(modpath, pic):
Expand Down