Skip to content

Commit

Permalink
Initial exploration around metadata returning None.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jun 27, 2024
1 parent f390168 commit 597776e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def _discover_resolvers():
return filter(None, declared)

@property
def metadata(self) -> _meta.PackageMetadata:
def metadata(self) -> _meta.PackageMetadata | None:
"""Return the parsed metadata for this Distribution.
The returned object will have keys that name the various bits of
Expand All @@ -440,18 +440,23 @@ def metadata(self) -> _meta.PackageMetadata:
Custom providers may provide the METADATA file or override this
property.
"""
# deferred for performance (python/cpython#109829)
from . import _adapters

opt_text = (
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 self._assemble_message(text)

@staticmethod
@pass_none
def _assemble_message(text: str) -> _meta.PackageMetadata:
# deferred for performance (python/cpython#109829)
from . import _adapters

return _adapters.Message(email.message_from_string(text))

@property
Expand Down

0 comments on commit 597776e

Please sign in to comment.