summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhippo91 <guillaume.peillex@gmail.com>2020-12-30 10:59:14 +0100
committerGitHub <noreply@github.com>2020-12-30 10:59:14 +0100
commita8bde99124c4213c26fd92a4b287786e5f4829ed (patch)
tree5bf140506efeba365b330bfb2a615d8e054d308b
parent99d9c77cc276b1c5f5d76d91282d05b5df3a2c21 (diff)
parentb6e03f20a58e0a7563ba13cce8c82d8906eabb44 (diff)
downloadastroid-git-a8bde99124c4213c26fd92a4b287786e5f4829ed.tar.gz
Merge pull request #869 from hippo91/fix_deprecated_importlib_methods
Fix deprecated importlib methods
-rw-r--r--ChangeLog3
-rw-r--r--astroid/interpreter/_import/spec.py17
2 files changed, 19 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 560544be..122a9eeb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/astroid/interpreter/_import/spec.py b/astroid/interpreter/_import/spec.py
index 48cae526..95b069e0 100644
--- a/astroid/interpreter/_import/spec.py
+++ b/astroid/interpreter/_import/spec.py
@@ -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>
@@ -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)),
@@ -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):