Skip to content

Commit

Permalink
Fix typing for specifiers.BaseSpecifier.filter() (#643)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii authored Dec 14, 2022
1 parent 5e446f7 commit 150c9a6
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/packaging/specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,23 @@
import abc
import itertools
import re
from typing import Callable, Iterable, Iterator, List, Optional, Set, Tuple, Union
from typing import (
Callable,
Iterable,
Iterator,
List,
Optional,
Set,
Tuple,
TypeVar,
Union,
)

from .utils import canonicalize_version
from .version import Version

UnparsedVersion = Union[Version, str]
UnparsedVersionVar = TypeVar("UnparsedVersionVar", bound=UnparsedVersion)
CallableOperator = Callable[[Version, str], bool]


Expand Down Expand Up @@ -85,8 +96,8 @@ def contains(self, item: str, prereleases: Optional[bool] = None) -> bool:

@abc.abstractmethod
def filter(
self, iterable: Iterable[UnparsedVersion], prereleases: Optional[bool] = None
) -> Iterator[UnparsedVersion]:
self, iterable: Iterable[UnparsedVersionVar], prereleases: Optional[bool] = None
) -> Iterator[UnparsedVersionVar]:
"""
Takes an iterable of items and filters them so that only items which
are contained within this specifier are allowed in it.
Expand Down Expand Up @@ -565,8 +576,8 @@ def contains(
return operator_callable(normalized_item, self.version)

def filter(
self, iterable: Iterable[UnparsedVersion], prereleases: Optional[bool] = None
) -> Iterator[UnparsedVersion]:
self, iterable: Iterable[UnparsedVersionVar], prereleases: Optional[bool] = None
) -> Iterator[UnparsedVersionVar]:
"""Filter items in the given iterable, that match the specifier.
:param iterable:
Expand Down Expand Up @@ -915,8 +926,8 @@ def contains(
return all(s.contains(item, prereleases=prereleases) for s in self._specs)

def filter(
self, iterable: Iterable[UnparsedVersion], prereleases: Optional[bool] = None
) -> Iterator[UnparsedVersion]:
self, iterable: Iterable[UnparsedVersionVar], prereleases: Optional[bool] = None
) -> Iterator[UnparsedVersionVar]:
"""Filter items in the given iterable, that match the specifiers in this set.
:param iterable:
Expand Down Expand Up @@ -972,8 +983,8 @@ def filter(
# which will filter out any pre-releases, unless there are no final
# releases.
else:
filtered: List[UnparsedVersion] = []
found_prereleases: List[UnparsedVersion] = []
filtered: List[UnparsedVersionVar] = []
found_prereleases: List[UnparsedVersionVar] = []

for item in iterable:
parsed_version = _coerce_version(item)
Expand Down

0 comments on commit 150c9a6

Please sign in to comment.