typing: Upgrade more Posting Iterables to Iterators.

This commit is contained in:
Brett Smith 2021-02-19 14:51:45 -05:00
parent b142b3e521
commit 4de5df9035
2 changed files with 5 additions and 4 deletions

View file

@ -43,6 +43,7 @@ from typing import (
Hashable,
IO,
Iterable,
Iterator,
NamedTuple,
NoReturn,
Optional,
@ -283,7 +284,7 @@ class SearchTerm(NamedTuple):
return cls(key, pattern)
return parse_search_term
def filter_postings(self, postings: Iterable[data.Posting]) -> Iterable[data.Posting]:
def filter_postings(self, postings: Iterable[data.Posting]) -> Iterator[data.Posting]:
return filters.filter_meta_match(
postings, self.meta_key, re.compile(self.pattern),
)

View file

@ -44,7 +44,7 @@ def audit_date(entries: Entries) -> Optional[datetime.date]:
return entry.date
return None
def filter_meta_equal(postings: Postings, key: MetaKey, value: MetaValue) -> Postings:
def filter_meta_equal(postings: Postings, key: MetaKey, value: MetaValue) -> Iterator[data.Posting]:
for post in postings:
try:
if post.meta[key] == value:
@ -52,7 +52,7 @@ def filter_meta_equal(postings: Postings, key: MetaKey, value: MetaValue) -> Pos
except KeyError:
pass
def filter_meta_match(postings: Postings, key: MetaKey, regexp: Regexp) -> Postings:
def filter_meta_match(postings: Postings, key: MetaKey, regexp: Regexp) -> Iterator[data.Posting]:
for post in postings:
try:
if re.search(regexp, post.meta[key]):
@ -60,7 +60,7 @@ def filter_meta_match(postings: Postings, key: MetaKey, regexp: Regexp) -> Posti
except (KeyError, TypeError):
pass
def filter_for_rt_id(postings: Postings, ticket_id: Union[int, str]) -> Postings:
def filter_for_rt_id(postings: Postings, ticket_id: Union[int, str]) -> Iterator[data.Posting]:
"""Filter postings with a primary RT ticket
This functions yields postings where the *first* rt-id matches the given