1- """
2- APIs exposing metadata from third-party Python packages.
3-
4- This codebase is shared between importlib.metadata in the stdlib
5- and importlib_metadata in PyPI. See
6- https://github.com/python/importlib_metadata/wiki/Development-Methodology
7- for more detail.
8- """
9-
101from __future__ import annotations
112
123import os
3829from itertools import starmap
3930from typing import Any , Iterable , List , Mapping , Match , Optional , Set , cast
4031
41- from ._typing import md_none
4232
4333__all__ = [
4434 'Distribution' ,
@@ -134,14 +124,6 @@ def valid(line: str):
134124 return line and not line .startswith ('#' )
135125
136126
137- class _EntryPointMatch (types .SimpleNamespace ):
138- module : str
139- attr : str
140- extras : str
141-
142-
143- from typing import Optional , List , cast , Match
144-
145127class EntryPoint :
146128 """An entry point as defined by Python packaging conventions.
147129
@@ -157,30 +139,6 @@ class EntryPoint:
157139 'attr'
158140 >>> ep.extras
159141 ['extra1', 'extra2']
160-
161- If the value package or module are not valid identifiers, a
162- ValueError is raised on access.
163-
164- >>> EntryPoint(name=None, group=None, value='invalid-name').module
165- Traceback (most recent call last):
166- ...
167- ValueError: ('Invalid object reference...invalid-name...
168- >>> EntryPoint(name=None, group=None, value='invalid-name').attr
169- Traceback (most recent call last):
170- ...
171- ValueError: ('Invalid object reference...invalid-name...
172- >>> EntryPoint(name=None, group=None, value='invalid-name').extras
173- Traceback (most recent call last):
174- ...
175- ValueError: ('Invalid object reference...invalid-name...
176-
177- The same thing happens on construction.
178-
179- >>> EntryPoint(name=None, group=None, value='invalid-name')
180- Traceback (most recent call last):
181- ...
182- ValueError: ('Invalid object reference...invalid-name...
183-
184142 """
185143
186144 pattern = re .compile (
@@ -411,17 +369,6 @@ def locate_file(self, path: str | os.PathLike[str]) -> SimplePath:
411369 """
412370 Given a path to a file in this distribution, return a SimplePath
413371 to it.
414-
415- This method is used by callers of ``Distribution.files()`` to
416- locate files within the distribution. If it's possible for a
417- Distribution to represent files in the distribution as
418- ``SimplePath`` objects, it should implement this method
419- to resolve such objects.
420-
421- Some Distribution providers may elect not to resolve SimplePath
422- objects within the distribution by raising a
423- NotImplementedError, but consumers of such a Distribution would
424- be unable to invoke ``Distribution.files()``.
425372 """
426373
427374 @classmethod
@@ -500,29 +447,26 @@ def metadata(self) -> _meta.PackageMetadata | None:
500447 Custom providers may provide the METADATA file or override this
501448 property.
502449 """
450+ # deferred for performance (python/cpython#109829)
451+ from . import _adapters
503452
504- text = (
453+ opt_text = (
505454 self .read_text ('METADATA' )
506455 or self .read_text ('PKG-INFO' )
507456 # This last clause is here to support old egg-info files. Its
508457 # effect is to just end up using the PathDistribution's self._path
509458 # (which points to the egg-info file) attribute unchanged.
510459 or self .read_text ('' )
511460 )
512- return self ._assemble_message (text )
513-
514- @staticmethod
515- @pass_none
516- def _assemble_message (text : str ) -> _meta .PackageMetadata :
517- # deferred for performance (python/cpython#109829)
518- from . import _adapters
519-
461+ text = cast (str , opt_text )
462+ if text is None :
463+ return None
520464 return _adapters .Message (email .message_from_string (text ))
521465
522466 @property
523467 def name (self ) -> str :
524468 """Return the 'Name' metadata for the distribution package."""
525- return md_none ( self .metadata ) ['Name' ]
469+ return self .metadata ['Name' ]
526470
527471 @property
528472 def _normalized_name (self ):
@@ -532,7 +476,7 @@ def _normalized_name(self):
532476 @property
533477 def version (self ) -> str :
534478 """Return the 'Version' metadata for the distribution package."""
535- return md_none ( self .metadata ) ['Version' ]
479+ return self .metadata ['Version' ]
536480
537481 @property
538482 def entry_points (self ) -> EntryPoints :
0 commit comments