2929from itertools import starmap
3030from typing import Any
3131
32- from . import _meta
3332from ._collections import FreezableDefaultDict , Pair
3433from ._context import ExceptionTrap
3534from ._functools import method_cache , noop , pass_none , passthrough
3635from ._itertools import always_iterable , bucket , unique_everseen
37- from ._meta import PackageMetadata , SimplePath
36+ from ._meta import (
37+ IDistribution ,
38+ IPackagePath ,
39+ PackageMetadata ,
40+ SimplePath ,
41+ )
3842
3943__all__ = [
4044 'Distribution' ,
4145 'DistributionFinder' ,
46+ 'IDistribution' ,
47+ 'IPackagePath' ,
4248 'MetadataNotFound' ,
4349 'PackageMetadata' ,
4450 'PackageNotFoundError' ,
@@ -210,7 +216,7 @@ class EntryPoint:
210216 value : str
211217 group : str
212218
213- dist : Distribution | None = None
219+ dist : IDistribution | None = None
214220
215221 def __init__ (self , name : str , value : str , group : str ) -> None :
216222 vars (self ).update (name = name , value = value , group = group )
@@ -375,7 +381,7 @@ class PackagePath(pathlib.PurePosixPath):
375381
376382 hash : FileHash | None
377383 size : int
378- dist : Distribution
384+ dist : IDistribution
379385
380386 def read_text (self , encoding : str = 'utf-8' ) -> str :
381387 return self .locate ().read_text (encoding = encoding )
@@ -538,7 +544,7 @@ def _discover_resolvers():
538544 return filter (None , declared )
539545
540546 @property
541- def metadata (self ) -> _meta . PackageMetadata :
547+ def metadata (self ) -> PackageMetadata :
542548 """Return the parsed metadata for this Distribution.
543549
544550 The returned object will have keys that name the various bits of
@@ -562,7 +568,7 @@ def metadata(self) -> _meta.PackageMetadata:
562568 return self ._assemble_message (self ._ensure_metadata_present (text ))
563569
564570 @staticmethod
565- def _assemble_message (text : str ) -> _meta . PackageMetadata :
571+ def _assemble_message (text : str ) -> PackageMetadata :
566572 # deferred for performance (python/cpython#109829)
567573 from . import _adapters
568574
@@ -602,10 +608,10 @@ def entry_points(self) -> EntryPoints:
602608 return EntryPoints ._from_text_for (self .read_text ('entry_points.txt' ), self )
603609
604610 @property
605- def files (self ) -> list [PackagePath ] | None :
611+ def files (self ) -> list [IPackagePath ] | None :
606612 """Files in this distribution.
607613
608- :return: List of PackagePath for this distribution or None
614+ :return: List of PackagePath-like objects for this distribution or None
609615
610616 Result is `None` if the metadata file that enumerates files
611617 (i.e. RECORD for dist-info, or installed-files.txt or
@@ -1096,7 +1102,7 @@ def _name_from_stem(stem):
10961102 return name
10971103
10981104
1099- def distribution (distribution_name : str ) -> Distribution :
1105+ def distribution (distribution_name : str ) -> IDistribution :
11001106 """Get the ``Distribution`` instance for the named package.
11011107
11021108 :param distribution_name: The name of the distribution package as a string.
@@ -1105,15 +1111,15 @@ def distribution(distribution_name: str) -> Distribution:
11051111 return Distribution .from_name (distribution_name )
11061112
11071113
1108- def distributions (** kwargs ) -> Iterable [Distribution ]:
1114+ def distributions (** kwargs ) -> Iterable [IDistribution ]:
11091115 """Get all ``Distribution`` instances in the current environment.
11101116
11111117 :return: An iterable of ``Distribution`` instances.
11121118 """
11131119 return Distribution .discover (** kwargs )
11141120
11151121
1116- def metadata (distribution_name : str ) -> _meta . PackageMetadata :
1122+ def metadata (distribution_name : str ) -> PackageMetadata :
11171123 """Get the metadata for the named package.
11181124
11191125 :param distribution_name: The name of the distribution package to query.
@@ -1157,7 +1163,7 @@ def entry_points(**params) -> EntryPoints:
11571163 return EntryPoints (eps ).select (** params )
11581164
11591165
1160- def files (distribution_name : str ) -> list [PackagePath ] | None :
1166+ def files (distribution_name : str ) -> list [IPackagePath ] | None :
11611167 """Return a list of files for the named package.
11621168
11631169 :param distribution_name: The name of the distribution package to query.
@@ -1197,15 +1203,15 @@ def _top_level_declared(dist):
11971203 return (dist .read_text ('top_level.txt' ) or '' ).split ()
11981204
11991205
1200- def _topmost (name : PackagePath ) -> str | None :
1206+ def _topmost (name : IPackagePath ) -> str | None :
12011207 """
12021208 Return the top-most parent as long as there is a parent.
12031209 """
12041210 top , * rest = name .parts
12051211 return top if rest else None
12061212
12071213
1208- def _get_toplevel_name (name : PackagePath ) -> str :
1214+ def _get_toplevel_name (name : IPackagePath ) -> str :
12091215 """
12101216 Infer a possibly importable module name from a name presumed on
12111217 sys.path.
0 commit comments