Changeset View
Standalone View
swh/storage/in_memory.py
Show First 20 Lines • Show All 516 Lines • ▼ Show 20 Lines | def revision_add(self, revisions: List[Revision]) -> Dict: | ||||
author=self._person_add(revision.author), | author=self._person_add(revision.author), | ||||
) | ) | ||||
self._revisions[revision.id] = revision | self._revisions[revision.id] = revision | ||||
self._objects[revision.id].append(("revision", revision.id)) | self._objects[revision.id].append(("revision", revision.id)) | ||||
count += 1 | count += 1 | ||||
return {"revision:add": count} | return {"revision:add": count} | ||||
def revision_missing(self, revisions): | def revision_missing(self, revisions: List[Sha1Git]) -> Iterable[Sha1Git]: | ||||
for id in revisions: | for id in revisions: | ||||
if id not in self._revisions: | if id not in self._revisions: | ||||
yield id | yield id | ||||
def revision_get(self, revisions): | def revision_get(self, revisions): | ||||
for id in revisions: | for id in revisions: | ||||
if id in self._revisions: | if id in self._revisions: | ||||
yield self._revisions.get(id).to_dict() | yield self._revisions.get(id).to_dict() | ||||
else: | else: | ||||
yield None | yield None | ||||
def _get_parent_revs(self, rev_id, seen, limit): | def _get_parent_revs(self, rev_id, seen, limit): | ||||
if limit and len(seen) >= limit: | if limit and len(seen) >= limit: | ||||
vlorentz: `Iterable[Optional[Dict[str, Any]]]` | |||||
Done Inline Actionsis return None and yield None in that context are similar? ^ that confuses me ardumont: is `return None` and `yield None` in that context are similar?
^ that confuses me | |||||
Done Inline Actions
(fixing my typo) ardumont: > is return None and yield None in that context are similar?
(fixing my typo)
Are `return… | |||||
Not Done Inline ActionsOh my bad, I didn't notice it's a generator. Then it should be return, not return None. vlorentz: Oh my bad, I didn't notice it's a generator. Then it should be `return`, not `return None`. | |||||
Done Inline Actionsheh, don't worry, that's the point of review, discussion and improvments ;) (i need to fix the build anyway because it's broken somehow... just checking the types test is not enough) ardumont: heh, don't worry, that's the point of review, discussion and improvments ;)
(i need to fix the… | |||||
Not Done Inline ActionsYou can remove Optional from the signature now vlorentz: You can remove Optional from the signature now | |||||
Done Inline Actionsbut if i do that, that won't type check anymore with the remaining part? (I'm back to my initial confusion) What did i miss? ardumont: but if i do that, that won't type check anymore with the remaining part?
(I'm back to my… | |||||
Not Done Inline Actionsit will, because Iterable[Optional[Dict[str, Any]]] is a supertype of Iterable[Dict[str, Any]] vlorentz: it will, because `Iterable[Optional[Dict[str, Any]]]` is a supertype of `Iterable[Dict[str… | |||||
Done Inline ActionsI did not realize, thanks. ardumont: I did not realize, thanks. | |||||
return | return | ||||
if rev_id in seen or rev_id not in self._revisions: | if rev_id in seen or rev_id not in self._revisions: | ||||
return | return | ||||
seen.add(rev_id) | seen.add(rev_id) | ||||
yield self._revisions[rev_id].to_dict() | yield self._revisions[rev_id].to_dict() | ||||
for parent in self._revisions[rev_id].parents: | for parent in self._revisions[rev_id].parents: | ||||
yield from self._get_parent_revs(parent, seen, limit) | yield from self._get_parent_revs(parent, seen, limit) | ||||
▲ Show 20 Lines • Show All 743 Lines • Show Last 20 Lines |
Iterable[Optional[Dict[str, Any]]]