20
20
from ._collections import FreezableDefaultDict , Pair
21
21
from ._compat import (
22
22
NullFinder ,
23
+ StrPath ,
23
24
install ,
24
25
pypy_partial ,
25
26
)
31
32
from importlib import import_module
32
33
from importlib .abc import MetaPathFinder
33
34
from 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
37
36
38
37
__all__ = [
39
38
'Distribution' ,
@@ -124,8 +123,8 @@ def read(text, filter_=None):
124
123
yield Pair (name , value )
125
124
126
125
@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 ('#' )
129
128
130
129
131
130
class DeprecatedTuple :
@@ -388,19 +387,19 @@ def from_name(cls, name: str) -> "Distribution":
388
387
if not name :
389
388
raise ValueError ("A distribution name is required." )
390
389
try :
391
- return next (cls .discover (name = name ))
390
+ return next (iter ( cls .discover (name = name ) ))
392
391
except StopIteration :
393
392
raise PackageNotFoundError (name )
394
393
395
394
@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.
398
397
399
398
Pass a ``context`` or pass keyword arguments for constructing
400
399
a context.
401
400
402
401
:context: A ``DistributionFinder.Context`` object.
403
- :return: Iterator of Distribution objects for all packages.
402
+ :return: Iterable of Distribution objects for all packages.
404
403
"""
405
404
context = kwargs .pop ('context' , None )
406
405
if context and kwargs :
@@ -411,7 +410,7 @@ def discover(cls, **kwargs) -> Iterator["Distribution"]:
411
410
)
412
411
413
412
@staticmethod
414
- def at (path : StrPath ) -> "PathDistribution " :
413
+ def at (path : StrPath ) -> "Distribution " :
415
414
"""Return a Distribution for the indicated metadata path
416
415
417
416
:param path: a string or path-like object
@@ -638,11 +637,11 @@ def path(self) -> List[str]:
638
637
return vars (self ).get ('path' , sys .path )
639
638
640
639
@abc .abstractmethod
641
- def find_distributions (self , context = Context ()) -> Iterator [Distribution ]:
640
+ def find_distributions (self , context = Context ()) -> Iterable [Distribution ]:
642
641
"""
643
642
Find distributions.
644
643
645
- Return an iterator of all Distribution instances capable of
644
+ Return an iterable of all Distribution instances capable of
646
645
loading the metadata for packages matching the ``context``,
647
646
a DistributionFinder.Context instance.
648
647
"""
@@ -775,11 +774,11 @@ class MetadataPathFinder(NullFinder, DistributionFinder):
775
774
776
775
def find_distributions (
777
776
self , context = DistributionFinder .Context ()
778
- ) -> Iterator ["PathDistribution" ]:
777
+ ) -> Iterable ["PathDistribution" ]:
779
778
"""
780
779
Find distributions.
781
780
782
- Return an iterator of all Distribution instances capable of
781
+ Return an iterable of all Distribution instances capable of
783
782
loading the metadata for packages matching ``context.name``
784
783
(or all names if ``None`` indicated) along the paths in the list
785
784
of directories ``context.path``.
@@ -863,10 +862,10 @@ def distribution(distribution_name) -> Distribution:
863
862
return Distribution .from_name (distribution_name )
864
863
865
864
866
- def distributions (** kwargs ) -> Iterator [Distribution ]:
865
+ def distributions (** kwargs ) -> Iterable [Distribution ]:
867
866
"""Get all ``Distribution`` instances in the current environment.
868
867
869
- :return: An iterator of ``Distribution`` instances.
868
+ :return: An iterable of ``Distribution`` instances.
870
869
"""
871
870
return Distribution .discover (** kwargs )
872
871
@@ -927,7 +926,7 @@ def requires(distribution_name) -> Optional[List[str]]:
927
926
"""
928
927
Return a list of requirements for the named package.
929
928
930
- :return: An iterator of requirements, suitable for
929
+ :return: An iterable of requirements, suitable for
931
930
packaging.requirement.Requirement.
932
931
"""
933
932
return distribution (distribution_name ).requires
0 commit comments