Skip to content

Commit 2c38c02

Browse files
correctmostDanielNoord
authored andcommitted
Improve performance of _get_zipimporters
_get_zipimporters can call isinstance millions of times when running pylint's import-error checker on a codebase like yt-dlp. Checking for None first avoids the overhead of invoking isinstance. Closes pylint-dev/pylint#9607.
1 parent 0ccc2e2 commit 2c38c02

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

astroid/interpreter/_import/spec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def _is_setuptools_namespace(location: pathlib.Path) -> bool:
341341

342342
def _get_zipimporters() -> Iterator[tuple[str, zipimport.zipimporter]]:
343343
for filepath, importer in sys.path_importer_cache.items():
344-
if isinstance(importer, zipimport.zipimporter):
344+
if importer is not None and isinstance(importer, zipimport.zipimporter):
345345
yield filepath, importer
346346

347347

0 commit comments

Comments
 (0)