1818import collections
1919
2020from .import _meta
21- from .compat import py39 ,py311
21+ from .compat import py39 ,py311 , stdlib
2222from ._collections import FreezableDefaultDict ,Pair
2323from ._compat import (
2424NullFinder ,
3030
3131from contextlib import suppress
3232from importlib import import_module
33- from importlib import metadata as _legacy
3433from importlib .abc import MetaPathFinder
3534from itertools import starmap
3635from typing import Any ,Iterable ,List ,Mapping ,Match ,Optional ,Set ,cast
3736
38- if sys .version_info >= (3 ,10 ):
39- from importlib .metadata import PackageMetadata as _legacy_Metadata
40- else :
41- from email .message import Message as _legacy_Metadata
42-
4337
4438__all__ = [
4539'Distribution' ,
@@ -382,7 +376,7 @@ def locate_file(self, path: str | os.PathLike[str]) -> SimplePath:
382376 """
383377
384378@classmethod
385- def from_name (cls ,name :str )-> Distribution | _legacy . Distribution :
379+ def from_name (cls ,name :str )-> stdlib . _DistributionOrLegacy :
386380"""Return the Distribution for the given package name.
387381
388382 :param name: The name of the distribution package to search for.
@@ -402,7 +396,7 @@ def from_name(cls, name: str) -> Distribution | _legacy.Distribution:
402396@classmethod
403397def discover (
404398cls ,* ,context :Optional [DistributionFinder .Context ]= None ,** kwargs
405- )-> Iterable [Distribution | _legacy . Distribution ]:
399+ )-> Iterable [stdlib . _DistributionOrLegacy ]:
406400"""Return an iterable of Distribution objects for all packages.
407401
408402 Pass a ``context`` or pass keyword arguments for constructing
@@ -948,7 +942,7 @@ def _name_from_stem(stem):
948942return name
949943
950944
951- def distribution (distribution_name :str )-> Distribution | _legacy . Distribution :
945+ def distribution (distribution_name :str )-> stdlib . _DistributionOrLegacy :
952946"""Get the ``Distribution`` instance for the named package.
953947
954948 :param distribution_name: The name of the distribution package as a string.
@@ -957,15 +951,15 @@ def distribution(distribution_name: str) -> Distribution | _legacy.Distribution:
957951return Distribution .from_name (distribution_name )
958952
959953
960- def distributions (** kwargs )-> Iterable [Distribution | _legacy . Distribution ]:
954+ def distributions (** kwargs )-> Iterable [stdlib . _DistributionOrLegacy ]:
961955"""Get all ``Distribution`` instances in the current environment.
962956
963957 :return: An iterable of ``Distribution`` instances.
964958 """
965959return Distribution .discover (** kwargs )
966960
967961
968- def metadata (distribution_name :str )-> _meta . PackageMetadata | _legacy_Metadata :
962+ def metadata (distribution_name :str )-> stdlib . _PackageMetadataOrLegacy :
969963"""Get the metadata for the named package.
970964
971965 :param distribution_name: The name of the distribution package to query.
@@ -1010,7 +1004,7 @@ def entry_points(**params) -> EntryPoints:
10101004
10111005def files (
10121006distribution_name :str ,
1013- )-> Optional [List [ PackagePath ] | List [ _legacy . PackagePath ] ]:
1007+ )-> Optional [stdlib . _List_PackagePathOrLegacy ]:
10141008"""Return a list of files for the named package.
10151009
10161010 :param distribution_name: The name of the distribution package to query.