3131
3232from contextlib import suppress
3333from importlib import import_module
34+ from importlib import metadata as _legacy
3435from importlib .abc import MetaPathFinder
3536from itertools import starmap
3637from typing import Any , Iterable , List , Mapping , Match , Optional , Set , cast
@@ -396,7 +397,7 @@ def locate_file(self, path: str | os.PathLike[str]) -> SimplePath:
396397 """
397398
398399 @classmethod
399- def from_name (cls , name : str ) -> Distribution :
400+ def from_name (cls , name : str ) -> Distribution | _legacy . Distribution :
400401 """Return the Distribution for the given package name.
401402
402403 :param name: The name of the distribution package to search for.
@@ -416,7 +417,7 @@ def from_name(cls, name: str) -> Distribution:
416417 @classmethod
417418 def discover (
418419 cls , * , context : Optional [DistributionFinder .Context ] = None , ** kwargs
419- ) -> Iterable [Distribution ]:
420+ ) -> Iterable [Distribution | _legacy . Distribution ]:
420421 """Return an iterable of Distribution objects for all packages.
421422
422423 Pass a ``context`` or pass keyword arguments for constructing
@@ -963,7 +964,7 @@ def _name_from_stem(stem):
963964 return name
964965
965966
966- def distribution (distribution_name : str ) -> Distribution :
967+ def distribution (distribution_name : str ) -> Distribution | _legacy . Distribution :
967968 """Get the ``Distribution`` instance for the named package.
968969
969970 :param distribution_name: The name of the distribution package as a string.
@@ -972,15 +973,15 @@ def distribution(distribution_name: str) -> Distribution:
972973 return Distribution .from_name (distribution_name )
973974
974975
975- def distributions (** kwargs ) -> Iterable [Distribution ]:
976+ def distributions (** kwargs ) -> Iterable [Distribution | _legacy . Distribution ]:
976977 """Get all ``Distribution`` instances in the current environment.
977978
978979 :return: An iterable of ``Distribution`` instances.
979980 """
980981 return Distribution .discover (** kwargs )
981982
982983
983- def metadata (distribution_name : str ) -> _meta .PackageMetadata :
984+ def metadata (distribution_name : str ) -> _meta .PackageMetadata | email . message . Message :
984985 """Get the metadata for the named package.
985986
986987 :param distribution_name: The name of the distribution package to query.
@@ -1023,7 +1024,9 @@ def entry_points(**params) -> EntryPoints:
10231024 return EntryPoints (eps ).select (** params )
10241025
10251026
1026- def files (distribution_name : str ) -> Optional [List [PackagePath ]]:
1027+ def files (
1028+ distribution_name : str ,
1029+ ) -> Optional [List [PackagePath ] | List [_legacy .PackagePath ]]:
10271030 """Return a list of files for the named package.
10281031
10291032 :param distribution_name: The name of the distribution package to query.
0 commit comments