From 9279db41ddeba474938e04d95038a43135a88b3d Mon Sep 17 00:00:00 2001 From: Facundo Tuesca Date: Tue, 29 Oct 2024 23:13:26 +0100 Subject: [PATCH] Fix entrypoints iteration in Python 3.9 Signed-off-by: Facundo Tuesca --- src/pip/_internal/utils/plugins.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/pip/_internal/utils/plugins.py b/src/pip/_internal/utils/plugins.py index cb0408af935..132b049ed12 100644 --- a/src/pip/_internal/utils/plugins.py +++ b/src/pip/_internal/utils/plugins.py @@ -1,6 +1,6 @@ import contextlib import logging -from importlib.metadata import EntryPoints, entry_points +from importlib.metadata import EntryPoint, entry_points from pathlib import Path from typing import Iterator, List @@ -10,12 +10,14 @@ _loaded_plugins: List[Plugin] = [] -def iter_entry_points(group_name: str) -> EntryPoints: +def iter_entry_points(group_name: str) -> List[EntryPoint]: + # Only Python >= 3.10 supports the `EntryPoints` class, so we return + # a list of `EntryPoint` instead. groups = entry_points() if hasattr(groups, "select"): # New interface in Python 3.10 and newer versions of the # importlib_metadata backport. - return groups.select(group=group_name) + return list(groups.select(group=group_name)) else: assert hasattr(groups, "get") # Older interface, deprecated in Python 3.10 and recent