Skip to content

Commit

Permalink
Add type hint to read_text result.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Apr 14, 2023
1 parent b0cce8a commit d390898
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from importlib import import_module
from importlib.abc import MetaPathFinder
from itertools import starmap
from typing import List, Mapping, Optional
from typing import List, Mapping, Optional, cast


__all__ = [
Expand Down Expand Up @@ -352,7 +352,7 @@ class Distribution(metaclass=abc.ABCMeta):
"""A Python distribution package."""

@abc.abstractmethod
def read_text(self, filename):
def read_text(self, filename) -> Optional[str]:
"""Attempt to load metadata file given by the name.
:param filename: The name of the file in the distribution info.
Expand Down Expand Up @@ -426,14 +426,15 @@ def metadata(self) -> _meta.PackageMetadata:
The returned object will have keys that name the various bits of
metadata. See PEP 566 for details.
"""
text = (
opt_text = (
self.read_text('METADATA')
or self.read_text('PKG-INFO')
# This last clause is here to support old egg-info files. Its
# effect is to just end up using the PathDistribution's self._path
# (which points to the egg-info file) attribute unchanged.
or self.read_text('')
)
text = cast(str, opt_text)
return _adapters.Message(email.message_from_string(text))

@property
Expand Down

0 comments on commit d390898

Please sign in to comment.