Skip to content

Commit fc2337d

Browse files
committed
Use LBYL
1 parent eaeae38 commit fc2337d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

importlib_resources/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def open(package: Package, file_name: FileName) -> BinaryIO:
4747
"""Return a file-like object opened for binary-reading of the resource."""
4848
file_name = _normalize_path(file_name)
4949
package = _get_package(package)
50-
try:
50+
if hasattr(package.__spec__.loader, 'open_resource'):
5151
return package.__spec__.loader.open_resource(file_name)
52-
except AttributeError:
52+
else:
5353
# Using pathlib doesn't work well here due to the lack of 'strict'
5454
# argument for pathlib.Path.resolve() prior to Python 3.6.
5555
absolute_package_path = os.path.abspath(package.__spec__.origin)

0 commit comments

Comments
 (0)