Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: pass through filter list type #430

Merged
merged 1 commit into from
May 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions packaging/specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Pattern,
Set,
Tuple,
TypeVar,
Union,
)

Expand All @@ -25,6 +26,7 @@

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


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

@abc.abstractmethod
def filter(
self, iterable: Iterable[UnparsedVersion], prereleases: Optional[bool] = None
) -> Iterable[UnparsedVersion]:
self, iterable: Iterable[VersionTypeVar], prereleases: Optional[bool] = None
) -> Iterable[VersionTypeVar]:
"""
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 @@ -205,8 +207,8 @@ def contains(
return operator_callable(normalized_item, self.version)

def filter(
self, iterable: Iterable[UnparsedVersion], prereleases: Optional[bool] = None
) -> Iterable[UnparsedVersion]:
self, iterable: Iterable[VersionTypeVar], prereleases: Optional[bool] = None
) -> Iterable[VersionTypeVar]:

yielded = False
found_prereleases = []
Expand Down Expand Up @@ -773,8 +775,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
) -> Iterable[UnparsedVersion]:
self, iterable: Iterable[VersionTypeVar], prereleases: Optional[bool] = None
) -> Iterable[VersionTypeVar]:

# Determine if we're forcing a prerelease or not, if we're not forcing
# one for this particular filter call, then we'll use whatever the
Expand All @@ -793,8 +795,11 @@ def filter(
# which will filter out any pre-releases, unless there are no final
# releases, and which will filter out LegacyVersion in general.
else:
filtered: List[UnparsedVersion] = []
found_prereleases: List[UnparsedVersion] = []
filtered: List[VersionTypeVar] = []
found_prereleases: List[VersionTypeVar] = []

item: UnparsedVersion
parsed_version: Union[Version, LegacyVersion]

for item in iterable:
# Ensure that we some kind of Version class for this item.
Expand Down