|
12 | 12 | from itertools import tee |
13 | 13 | from typing import Any |
14 | 14 | from typing import NamedTuple |
15 | | -from typing import Optional |
16 | 15 | from typing import TYPE_CHECKING |
17 | 16 |
|
| 17 | +from ._parser import EntryPair |
18 | 18 | from ._parser import ParseResult |
19 | 19 | from ._types import EntryData |
20 | 20 | from ._types import EntryForUpdate |
|
46 | 46 | HASH_CHANGED_LIMIT = 24 |
47 | 47 |
|
48 | 48 |
|
49 | | -EntryPairs = Iterable[tuple[EntryData, Optional[EntryForUpdate]]] |
50 | | - |
51 | | - |
52 | 49 | @dataclass(frozen=True) |
53 | 50 | class Decider: |
54 | 51 | """Decide whether a feed or entry should be updated. |
@@ -89,8 +86,8 @@ def make_intents( |
89 | 86 | now: datetime, |
90 | 87 | global_now: datetime, |
91 | 88 | config: UpdateConfig, |
92 | | - result: ParseResult[FeedForUpdate, ParseError], |
93 | | - entry_pairs: EntryPairs, |
| 89 | + result: ParseResult, |
| 90 | + entry_pairs: Iterable[EntryPair], |
94 | 91 | ) -> tuple[FeedUpdateIntent, Iterable[EntryUpdateIntent]]: |
95 | 92 | decider = cls( |
96 | 93 | old_feed, |
@@ -194,7 +191,9 @@ def debug(msg: str, *args: Any) -> None: |
194 | 191 | debug("entry not updated, skipping") |
195 | 192 | return None |
196 | 193 |
|
197 | | - def get_entries_to_update(self, pairs: EntryPairs) -> Iterable[EntryUpdateIntent]: |
| 194 | + def get_entries_to_update( |
| 195 | + self, pairs: Iterable[EntryPair] |
| 196 | + ) -> Iterable[EntryUpdateIntent]: |
198 | 197 | for feed_order, (new, old) in reversed(list(enumerate(pairs))): |
199 | 198 | # This may fail if we ever implement changing the feed URL |
200 | 199 | # in response to a permanent redirect. |
@@ -235,8 +234,8 @@ def get_feed_to_update( |
235 | 234 |
|
236 | 235 | def update( |
237 | 236 | self, |
238 | | - result: ParseResult[FeedForUpdate, ParseError], |
239 | | - entry_pairs: EntryPairs, |
| 237 | + result: ParseResult, |
| 238 | + entry_pairs: Iterable[EntryPair], |
240 | 239 | ) -> tuple[FeedUpdateIntent, Iterable[EntryUpdateIntent]]: |
241 | 240 |
|
242 | 241 | # TODO: move entries_to_update in FeedToUpdate, maybe? |
@@ -394,7 +393,7 @@ def update(self, filter: FeedFilter) -> Iterable[UpdateResult]: |
394 | 393 | # Storing the exceptions until the end of the generator |
395 | 394 | # might cause memory issues, but the caller may need to raise them. |
396 | 395 | # TODO: Rework update pipeline to support process_feed_for_update() exceptions. |
397 | | - parser_process_feeds_for_update_errors = [] |
| 396 | + parser_process_feeds_for_update_errors: list[ParseResult] = [] |
398 | 397 |
|
399 | 398 | def parser_process_feeds_for_update( |
400 | 399 | feeds: Iterable[FeedForUpdate], |
@@ -428,7 +427,7 @@ def parser_process_feeds_for_update( |
428 | 427 | def process_parse_result( |
429 | 428 | self, |
430 | 429 | config: UpdateConfig, |
431 | | - result: ParseResult[FeedForUpdate, ParseError], |
| 430 | + result: ParseResult, |
432 | 431 | ) -> tuple[str, UpdatedFeed | None | Exception]: |
433 | 432 | feed, value, _ = result |
434 | 433 |
|
@@ -470,13 +469,13 @@ def process_parse_result( |
470 | 469 |
|
471 | 470 | return feed.url, UpdatedFeed(feed.url, *counts, total - sum(counts)) |
472 | 471 |
|
473 | | - def get_entry_pairs(self, result: ParsedFeed) -> EntryPairs: |
| 472 | + def get_entry_pairs(self, result: ParsedFeed) -> Iterable[EntryPair]: |
474 | 473 | # give storage a chance to consume entries in a streaming fashion |
475 | 474 | entries1, entries2 = tee(result.entries) |
476 | 475 | entries_for_update = self.reader._storage.get_entries_for_update( |
477 | 476 | (e.feed_url, e.id) for e in entries1 |
478 | 477 | ) |
479 | | - return zip(entries2, entries_for_update, strict=True) |
| 478 | + return map(EntryPair._make, zip(entries2, entries_for_update, strict=True)) |
480 | 479 |
|
481 | 480 | def update_feed( |
482 | 481 | self, |
|
0 commit comments