Skip to content

Commit

Permalink
Make mypy happier
Browse files Browse the repository at this point in the history
  • Loading branch information
brettcannon committed Oct 31, 2017
1 parent fc2337d commit e02ddea
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion importlib_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from typing import Iterator, Union
from typing.io import BinaryIO

from . import abc as resources_abc


Package = Union[types.ModuleType, str]
if sys.version_info >= (3, 6):
Expand Down Expand Up @@ -48,7 +50,9 @@ def open(package: Package, file_name: FileName) -> BinaryIO:
file_name = _normalize_path(file_name)
package = _get_package(package)
if hasattr(package.__spec__.loader, 'open_resource'):
return package.__spec__.loader.open_resource(file_name)
reader = typing.cast(resources_abc.ResourceReader,
package.__spec__.loader)
return reader.open_resource(file_name)
else:
# Using pathlib doesn't work well here due to the lack of 'strict'
# argument for pathlib.Path.resolve() prior to Python 3.6.
Expand Down

0 comments on commit e02ddea

Please sign in to comment.