Skip to content

Commit

Permalink
Demonstrate behaviour of SpecifierSet.__iter__ (#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Jul 17, 2022
1 parent e404434 commit 2bd5da3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/specifiers.rst
Expand Up @@ -30,6 +30,10 @@ Usage
>>> combined_spec &= "!=1.1"
>>> combined_spec
<SpecifierSet('!=1.1,>=1.0,~=1.0')>
>>> # We can iterate over the SpecifierSet to recover the
>>> # individual specifiers
>>> sorted(combined_spec, key=str)
[<Specifier('!=1.1')>, <Specifier('>=1.0')>, <Specifier('~=1.0')>]
>>> # Create a few versions to check for contains.
>>> v1 = Version("1.0a5")
>>> v2 = Version("1.0")
Expand Down
3 changes: 3 additions & 0 deletions packaging/specifiers.py
Expand Up @@ -823,6 +823,9 @@ def __iter__(self) -> Iterator[Specifier]:
"""
Returns an iterator over all the underlying :class:`Specifier` instances
in this specifier set.
>>> sorted(SpecifierSet(">=1.0.0,!=1.0.1"), key=str)
[<Specifier('!=1.0.1')>, <Specifier('>=1.0.0')>]
"""
return iter(self._specs)

Expand Down

0 comments on commit 2bd5da3

Please sign in to comment.