Skip to content

Commit

Permalink
Merge pull request #869 from hippo91/fix_deprecated_importlib_methods
Browse files Browse the repository at this point in the history
Fix deprecated importlib methods
  • Loading branch information
hippo91 committed Dec 30, 2020
2 parents 99d9c77 + b6e03f2 commit a8bde99
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ChangeLog
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
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

0 comments on commit a8bde99

Please sign in to comment.