2020from ._collections import FreezableDefaultDict , Pair
2121from ._compat import (
2222 NullFinder ,
23+ StrPath ,
2324 install ,
2425 pypy_partial ,
2526)
3132from importlib import import_module
3233from importlib .abc import MetaPathFinder
3334from itertools import starmap
34- from typing import Iterator , List , Mapping , Optional , Set , Union , cast
35-
36- StrPath = Union [str , "os.PathLike[str]" ]
35+ from typing import Iterable , List , Mapping , Optional , Set , cast
3736
3837__all__ = [
3938 'Distribution' ,
@@ -124,8 +123,8 @@ def read(text, filter_=None):
124123 yield Pair (name , value )
125124
126125 @staticmethod
127- def valid (line : str ) -> bool :
128- return bool ( line ) and not line .startswith ('#' )
126+ def valid (line : str ):
127+ return line and not line .startswith ('#' )
129128
130129
131130class DeprecatedTuple :
@@ -388,19 +387,19 @@ def from_name(cls, name: str) -> "Distribution":
388387 if not name :
389388 raise ValueError ("A distribution name is required." )
390389 try :
391- return next (cls .discover (name = name ))
390+ return next (iter ( cls .discover (name = name ) ))
392391 except StopIteration :
393392 raise PackageNotFoundError (name )
394393
395394 @classmethod
396- def discover (cls , ** kwargs ) -> Iterator ["Distribution" ]:
397- """Return an iterator of Distribution objects for all packages.
395+ def discover (cls , ** kwargs ) -> Iterable ["Distribution" ]:
396+ """Return an iterable of Distribution objects for all packages.
398397
399398 Pass a ``context`` or pass keyword arguments for constructing
400399 a context.
401400
402401 :context: A ``DistributionFinder.Context`` object.
403- :return: Iterator of Distribution objects for all packages.
402+ :return: Iterable of Distribution objects for all packages.
404403 """
405404 context = kwargs .pop ('context' , None )
406405 if context and kwargs :
@@ -411,7 +410,7 @@ def discover(cls, **kwargs) -> Iterator["Distribution"]:
411410 )
412411
413412 @staticmethod
414- def at (path : StrPath ) -> "PathDistribution " :
413+ def at (path : StrPath ) -> "Distribution " :
415414 """Return a Distribution for the indicated metadata path
416415
417416 :param path: a string or path-like object
@@ -638,11 +637,11 @@ def path(self) -> List[str]:
638637 return vars (self ).get ('path' , sys .path )
639638
640639 @abc .abstractmethod
641- def find_distributions (self , context = Context ()) -> Iterator [Distribution ]:
640+ def find_distributions (self , context = Context ()) -> Iterable [Distribution ]:
642641 """
643642 Find distributions.
644643
645- Return an iterator of all Distribution instances capable of
644+ Return an iterable of all Distribution instances capable of
646645 loading the metadata for packages matching the ``context``,
647646 a DistributionFinder.Context instance.
648647 """
@@ -775,11 +774,11 @@ class MetadataPathFinder(NullFinder, DistributionFinder):
775774
776775 def find_distributions (
777776 self , context = DistributionFinder .Context ()
778- ) -> Iterator ["PathDistribution" ]:
777+ ) -> Iterable ["PathDistribution" ]:
779778 """
780779 Find distributions.
781780
782- Return an iterator of all Distribution instances capable of
781+ Return an iterable of all Distribution instances capable of
783782 loading the metadata for packages matching ``context.name``
784783 (or all names if ``None`` indicated) along the paths in the list
785784 of directories ``context.path``.
@@ -863,10 +862,10 @@ def distribution(distribution_name) -> Distribution:
863862 return Distribution .from_name (distribution_name )
864863
865864
866- def distributions (** kwargs ) -> Iterator [Distribution ]:
865+ def distributions (** kwargs ) -> Iterable [Distribution ]:
867866 """Get all ``Distribution`` instances in the current environment.
868867
869- :return: An iterator of ``Distribution`` instances.
868+ :return: An iterable of ``Distribution`` instances.
870869 """
871870 return Distribution .discover (** kwargs )
872871
@@ -927,7 +926,7 @@ def requires(distribution_name) -> Optional[List[str]]:
927926 """
928927 Return a list of requirements for the named package.
929928
930- :return: An iterator of requirements, suitable for
929+ :return: An iterable of requirements, suitable for
931930 packaging.requirement.Requirement.
932931 """
933932 return distribution (distribution_name ).requires
0 commit comments