Skip to content

Commit d390898

Browse files
committed
Add type hint to read_text result.
1 parent b0cce8a commit d390898

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

importlib_metadata/__init__.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from importlib import import_module
3232
from importlib.abc import MetaPathFinder
3333
from itertools import starmap
34-
from typing import List, Mapping, Optional
34+
from typing import List, Mapping, Optional, cast
3535

3636

3737
__all__ = [
@@ -352,7 +352,7 @@ class Distribution(metaclass=abc.ABCMeta):
352352
"""A Python distribution package."""
353353

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

439440
@property

0 commit comments

Comments
 (0)