Skip to content

Commit 2bb4cc0

Browse files
committed
Updates from PR Review
1 parent b0a4c08 commit 2bb4cc0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

newsfragments/4262.feature.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Improved `AttributeError` error message if ``pkg_resources.EntryPoint.require`` is called without extras or distribution
2+
Gracefully "do nothing" when trying to activate a ``pkg_resources.Distribution`` with a `None` location, rather than raising a `TypeError`
3+
-- by :user:`Avasam`

pkg_resources/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ def _validate_resource_path(path):
16361636
)
16371637

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

24942494
def require(self, env=None, installer=None):
24952495
if not self.dist:
2496-
raise UnknownExtra("Can't require() without a distribution", self)
2496+
error_cls = UnknownExtra if self.extras else AttributeError
2497+
raise error_cls("Can't require() without a distribution", self)
24972498

24982499
# Get the requirements for this entry point with all its extras and
24992500
# then resolve them. We have to pass `extras` along when resolving so
@@ -2825,7 +2826,7 @@ def activate(self, path=None, replace=False):
28252826
if path is None:
28262827
path = sys.path
28272828
self.insert_on(path, replace=replace)
2828-
if path is sys.path and self.location:
2829+
if path is sys.path:
28292830
fixup_namespace_packages(self.location)
28302831
for pkg in self._get_metadata('namespace_packages.txt'):
28312832
if pkg in sys.modules:

0 commit comments

Comments
 (0)