summaryrefslogtreecommitdiff
path: root/pkg_resources
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2021-12-03 23:02:26 -0500
committerJason R. Coombs <jaraco@jaraco.com>2021-12-03 23:02:26 -0500
commitbe4466cc15011d337dba3a49867a7d597d2f36e4 (patch)
treec344861e550c26929c1993a00f606f776fc81cfe /pkg_resources
parenta91bd3e55012333de956f05191e7d485ed93812f (diff)
downloadpython-setuptools-git-be4466cc15011d337dba3a49867a7d597d2f36e4.tar.gz
Re-implement yield_lines as a singledispatch function.
Diffstat (limited to 'pkg_resources')
-rw-r--r--pkg_resources/__init__.py25
1 files changed, 13 insertions, 12 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py
index 42129d5b..955fdc48 100644
--- a/pkg_resources/__init__.py
+++ b/pkg_resources/__init__.py
@@ -2396,18 +2396,19 @@ def _set_parent_ns(packageName):
setattr(sys.modules[parent], name, sys.modules[packageName])
-def yield_lines(strs):
- """Yield non-empty/non-comment lines of a string or sequence"""
- if isinstance(strs, str):
- for s in strs.splitlines():
- s = s.strip()
- # skip blank lines/comments
- if s and not s.startswith('#'):
- yield s
- else:
- for ss in strs:
- for s in yield_lines(ss):
- yield s
+def _nonblank(str):
+ return str and not str.startswith('#')
+
+
+@functools.singledispatch
+def yield_lines(iterable):
+ """Yield valid lines of a string or iterable"""
+ return itertools.chain.from_iterable(map(yield_lines, iterable))
+
+
+@yield_lines.register(str)
+def _(text):
+ return filter(_nonblank, map(str.strip, text.splitlines()))
MODULE = re.compile(r"\w+(\.\w+)*$").match