summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2017-09-09 12:04:12 -0400
committerJason R. Coombs <jaraco@jaraco.com>2017-09-09 12:07:50 -0400
commit9ff9a0d6a79b8d4b610f8e8780586dd2114856d0 (patch)
tree3c3fedf8bd026311ce6d066f111370f4530efbc8
parenteea94d01a59f7f43dd41c271ff6849995a4d1e7e (diff)
downloadpython-setuptools-git-9ff9a0d6a79b8d4b610f8e8780586dd2114856d0.tar.gz
Create a NoDists factory for returning no dists, whose boolean value is False.
-rw-r--r--pkg_resources/__init__.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index d9154e6d..82b4ce51 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -2045,12 +2045,29 @@ def find_on_path(importer, path_item, only=False):
if not only and _is_egg_path(entry) else
resolve_egg_link(fullpath)
if not only and lower.endswith('.egg-link') else
- ()
+ NoDists()(fullpath)
)
for dist in dists:
yield dist
+class NoDists:
+ """
+ >>> bool(NoDists())
+ False
+
+ >>> list(NoDists()('anything'))
+ []
+ """
+ def __bool__(self):
+ return False
+ if six.PY2:
+ __nonzero__ = __bool__
+
+ def __call__(self, fullpath):
+ return iter(())
+
+
def safe_listdir(path):
"""
Attempt to list contents of path, but suppress some exceptions.