Skip to content

Commit fb90dc3

Browse files
committed
Runtime fixes to make typing annotations work
1 parent 9b081af commit fb90dc3

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

pkg_resources/__init__.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import time
2828
import re
2929
import types
30-
from typing import List, Protocol
30+
from typing import Dict, List, Protocol
3131
import zipfile
3232
import zipimport
3333
import warnings
@@ -920,10 +920,10 @@ def find_plugins(self, plugin_env, full_env=None, installer=None, fallback=True)
920920
# success, no need to try any more versions of this project
921921
break
922922

923-
distributions = list(distributions)
924-
distributions.sort()
923+
sorted_distributions = list(distributions)
924+
sorted_distributions.sort()
925925

926-
return distributions, error_info
926+
return sorted_distributions, error_info
927927

928928
def require(self, *requirements):
929929
"""Ensure that distributions matching `requirements` are activated
@@ -1636,7 +1636,7 @@ def _validate_resource_path(path):
16361636
)
16371637

16381638
def _get(self, path) -> bytes:
1639-
if hasattr(self.loader, 'get_data'):
1639+
if self.loader and hasattr(self.loader, 'get_data'):
16401640
return self.loader.get_data(path)
16411641
raise NotImplementedError(
16421642
"Can't perform this operation for loaders without 'get_data()'"
@@ -2492,7 +2492,7 @@ def resolve(self):
24922492
raise ImportError(str(exc)) from exc
24932493

24942494
def require(self, env=None, installer=None):
2495-
if self.extras and not self.dist:
2495+
if not self.dist:
24962496
raise UnknownExtra("Can't require() without a distribution", self)
24972497

24982498
# Get the requirements for this entry point with all its extras and
@@ -2559,11 +2559,11 @@ def parse_group(cls, group, lines, dist=None):
25592559
def parse_map(cls, data, dist=None):
25602560
"""Parse a map of entry point groups"""
25612561
if isinstance(data, dict):
2562-
data = data.items()
2562+
_data = data.items()
25632563
else:
2564-
data = split_sections(data)
2565-
maps = {}
2566-
for group, lines in data:
2564+
_data = split_sections(data)
2565+
maps: Dict[str, Dict[str, "EntryPoint"]] = {}
2566+
for group, lines in _data:
25672567
if group is None:
25682568
if not lines:
25692569
continue
@@ -2825,7 +2825,7 @@ def activate(self, path=None, replace=False):
28252825
if path is None:
28262826
path = sys.path
28272827
self.insert_on(path, replace=replace)
2828-
if path is sys.path:
2828+
if path is sys.path and self.location:
28292829
fixup_namespace_packages(self.location)
28302830
for pkg in self._get_metadata('namespace_packages.txt'):
28312831
if pkg in sys.modules:
@@ -2893,15 +2893,13 @@ def load_entry_point(self, group, name):
28932893

28942894
def get_entry_map(self, group=None):
28952895
"""Return the entry point map for `group`, or the full entry map"""
2896-
try:
2897-
ep_map = self._ep_map
2898-
except AttributeError:
2899-
ep_map = self._ep_map = EntryPoint.parse_map(
2896+
if not hasattr(self, "_ep_map"):
2897+
self._ep_map = EntryPoint.parse_map(
29002898
self._get_metadata('entry_points.txt'), self
29012899
)
29022900
if group is not None:
2903-
return ep_map.get(group, {})
2904-
return ep_map
2901+
return self._ep_map.get(group, {})
2902+
return self._ep_map
29052903

29062904
def get_entry_info(self, group, name):
29072905
"""Return the EntryPoint object for `group`+`name`, or ``None``"""

0 commit comments

Comments
 (0)