3030
3131from contextlib import suppress
3232from importlib import import_module
33+ from importlib import metadata as _legacy
3334from importlib .abc import MetaPathFinder
3435from itertools import starmap
3536from typing import Any , Iterable , List , Mapping , Match , Optional , Set , cast
@@ -375,7 +376,7 @@ def locate_file(self, path: str | os.PathLike[str]) -> SimplePath:
375376 """
376377
377378 @classmethod
378- def from_name (cls , name : str ) -> Distribution :
379+ def from_name (cls , name : str ) -> Distribution | _legacy . Distribution :
379380 """Return the Distribution for the given package name.
380381
381382 :param name: The name of the distribution package to search for.
@@ -395,7 +396,7 @@ def from_name(cls, name: str) -> Distribution:
395396 @classmethod
396397 def discover (
397398 cls , * , context : Optional [DistributionFinder .Context ] = None , ** kwargs
398- ) -> Iterable [Distribution ]:
399+ ) -> Iterable [Distribution | _legacy . Distribution ]:
399400 """Return an iterable of Distribution objects for all packages.
400401
401402 Pass a ``context`` or pass keyword arguments for constructing
@@ -941,7 +942,7 @@ def _name_from_stem(stem):
941942 return name
942943
943944
944- def distribution (distribution_name : str ) -> Distribution :
945+ def distribution (distribution_name : str ) -> Distribution | _legacy . Distribution :
945946 """Get the ``Distribution`` instance for the named package.
946947
947948 :param distribution_name: The name of the distribution package as a string.
@@ -950,15 +951,15 @@ def distribution(distribution_name: str) -> Distribution:
950951 return Distribution .from_name (distribution_name )
951952
952953
953- def distributions (** kwargs ) -> Iterable [Distribution ]:
954+ def distributions (** kwargs ) -> Iterable [Distribution | _legacy . Distribution ]:
954955 """Get all ``Distribution`` instances in the current environment.
955956
956957 :return: An iterable of ``Distribution`` instances.
957958 """
958959 return Distribution .discover (** kwargs )
959960
960961
961- def metadata (distribution_name : str ) -> _meta .PackageMetadata :
962+ def metadata (distribution_name : str ) -> _meta .PackageMetadata | email . message . Message :
962963 """Get the metadata for the named package.
963964
964965 :param distribution_name: The name of the distribution package to query.
@@ -1001,7 +1002,9 @@ def entry_points(**params) -> EntryPoints:
10011002 return EntryPoints (eps ).select (** params )
10021003
10031004
1004- def files (distribution_name : str ) -> Optional [List [PackagePath ]]:
1005+ def files (
1006+ distribution_name : str ,
1007+ ) -> Optional [List [PackagePath ] | List [_legacy .PackagePath ]]:
10051008 """Return a list of files for the named package.
10061009
10071010 :param distribution_name: The name of the distribution package to query.
0 commit comments