Skip to content

Commit e54a040

Browse files
committed
Save a call to isfile() and an attempt to build a zipp.Path.
1 parent 9f709bd commit e54a040

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

importlib_metadata/__init__.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
NotADirectoryError,
2525
PermissionError,
2626
pathlib,
27-
PYPY_OPEN_BUG,
2827
ModuleNotFoundError,
2928
MetaPathFinder,
3029
email_message_from_string,
@@ -418,25 +417,20 @@ def _search_paths(cls, name, paths):
418417
return itertools.chain.from_iterable(
419418
cls._search_path(path, name) for path in paths)
420419

421-
@staticmethod
422-
def _switch_path(path):
423-
if not PYPY_OPEN_BUG or os.path.isfile(path): # pragma: no branch
424-
with suppress(Exception):
425-
return zipp.Path(path)
426-
return pathlib.Path(path)
427-
428420
@classmethod
429421
def _search_path(cls, root, name):
430422
# This function is microoptimized by avoiding the use of regexes and
431423
# using strs rather than Path objects.
432424
root = root or '.'
433425
try:
434426
children = os.listdir(root)
427+
path_type = pathlib.Path
435428
except Exception:
436429
try:
437430
with zipfile.ZipFile(root) as zf:
438431
children = [os.path.split(child)[0]
439432
for child in zf.namelist()]
433+
path_type = zipp.Path
440434
except Exception:
441435
return
442436
if name is not None:
@@ -456,7 +450,7 @@ def _search_path(cls, root, name):
456450
or n_low.startswith(prefix) and n_low.endswith(suffixes)
457451
# legacy case:
458452
or root_is_egg and n_low == 'egg-info'):
459-
yield cls._switch_path(root) / child
453+
yield path_type(root, child)
460454

461455

462456
class PathDistribution(Distribution):

importlib_metadata/_compat.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ def py2_message_from_string(text): # nocoverpy3
111111
email.message_from_string
112112
)
113113

114-
# https://bitbucket.org/pypy/pypy/issues/3021/ioopen-directory-leaks-a-file-descriptor
115-
PYPY_OPEN_BUG = getattr(sys, 'pypy_version_info', (9, 9, 9))[:3] <= (7, 1, 1)
116-
117114

118115
class PyPy_repr:
119116
"""

0 commit comments

Comments
 (0)