18
18
import collections
19
19
20
20
from . import _meta
21
- from .compat import py39 , py311
21
+ from .compat import py39 , py311 , stdlib
22
22
from ._collections import FreezableDefaultDict , Pair
23
23
from ._compat import (
24
24
NullFinder ,
30
30
31
31
from contextlib import suppress
32
32
from importlib import import_module
33
- from importlib import metadata as _legacy
34
33
from importlib .abc import MetaPathFinder
35
34
from itertools import starmap
36
35
from typing import Any , Iterable , List , Mapping , Match , Optional , Set , cast
37
36
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
-
43
37
44
38
__all__ = [
45
39
'Distribution' ,
@@ -382,7 +376,7 @@ def locate_file(self, path: str | os.PathLike[str]) -> SimplePath:
382
376
"""
383
377
384
378
@classmethod
385
- def from_name (cls , name : str ) -> Distribution | _legacy . Distribution :
379
+ def from_name (cls , name : str ) -> stdlib . _DistributionOrLegacy :
386
380
"""Return the Distribution for the given package name.
387
381
388
382
:param name: The name of the distribution package to search for.
@@ -402,7 +396,7 @@ def from_name(cls, name: str) -> Distribution | _legacy.Distribution:
402
396
@classmethod
403
397
def discover (
404
398
cls , * , context : Optional [DistributionFinder .Context ] = None , ** kwargs
405
- ) -> Iterable [Distribution | _legacy . Distribution ]:
399
+ ) -> Iterable [stdlib . _DistributionOrLegacy ]:
406
400
"""Return an iterable of Distribution objects for all packages.
407
401
408
402
Pass a ``context`` or pass keyword arguments for constructing
@@ -948,7 +942,7 @@ def _name_from_stem(stem):
948
942
return name
949
943
950
944
951
- def distribution (distribution_name : str ) -> Distribution | _legacy . Distribution :
945
+ def distribution (distribution_name : str ) -> stdlib . _DistributionOrLegacy :
952
946
"""Get the ``Distribution`` instance for the named package.
953
947
954
948
:param distribution_name: The name of the distribution package as a string.
@@ -957,15 +951,15 @@ def distribution(distribution_name: str) -> Distribution | _legacy.Distribution:
957
951
return Distribution .from_name (distribution_name )
958
952
959
953
960
- def distributions (** kwargs ) -> Iterable [Distribution | _legacy . Distribution ]:
954
+ def distributions (** kwargs ) -> Iterable [stdlib . _DistributionOrLegacy ]:
961
955
"""Get all ``Distribution`` instances in the current environment.
962
956
963
957
:return: An iterable of ``Distribution`` instances.
964
958
"""
965
959
return Distribution .discover (** kwargs )
966
960
967
961
968
- def metadata (distribution_name : str ) -> _meta . PackageMetadata | _legacy_Metadata :
962
+ def metadata (distribution_name : str ) -> stdlib . _PackageMetadataOrLegacy :
969
963
"""Get the metadata for the named package.
970
964
971
965
:param distribution_name: The name of the distribution package to query.
@@ -1010,7 +1004,7 @@ def entry_points(**params) -> EntryPoints:
1010
1004
1011
1005
def files (
1012
1006
distribution_name : str ,
1013
- ) -> Optional [List [ PackagePath ] | List [ _legacy . PackagePath ] ]:
1007
+ ) -> Optional [stdlib . _List_PackagePathOrLegacy ]:
1014
1008
"""Return a list of files for the named package.
1015
1009
1016
1010
:param distribution_name: The name of the distribution package to query.
0 commit comments