Skip to content

Commit 35c25b4

Browse files
committed
Merge branch 'skip_zipp_not_a_file' into 'master'
Skip zipp.Path when it is not a file See merge request python-devs/importlib_metadata!75
2 parents 489ab8e + 898b200 commit 35c25b4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

importlib_metadata/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import unicode_literals, absolute_import
22

33
import io
4+
import os
45
import re
56
import abc
67
import csv
@@ -22,6 +23,7 @@
2223
NotADirectoryError,
2324
PermissionError,
2425
pathlib,
26+
PYPY_OPEN_BUG,
2527
ModuleNotFoundError,
2628
MetaPathFinder,
2729
email_message_from_string,
@@ -366,8 +368,9 @@ def _search_paths(cls, pattern, paths):
366368

367369
@staticmethod
368370
def _switch_path(path):
369-
with suppress(Exception):
370-
return zipp.Path(path)
371+
if not PYPY_OPEN_BUG or os.path.isfile(path): # pragma: no branch
372+
with suppress(Exception):
373+
return zipp.Path(path)
371374
return pathlib.Path(path)
372375

373376
@classmethod

importlib_metadata/_compat.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,6 @@ def py2_message_from_string(text): # nocoverpy3
8686
if sys.version_info < (3,) else
8787
email.message_from_string
8888
)
89+
90+
# https://bitbucket.org/pypy/pypy/issues/3021/ioopen-directory-leaks-a-file-descriptor
91+
PYPY_OPEN_BUG = getattr(sys, 'pypy_version_info', (9, 9, 9))[:3] <= (7, 1, 1)

0 commit comments

Comments
 (0)