Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/model.py
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | def parents(self) -> Iterator["RevisionEntry"]: | ||||
if self._parents_entries is None: | if self._parents_entries is None: | ||||
raise RuntimeError( | raise RuntimeError( | ||||
"Parents of this node has not yet been retrieved. " | "Parents of this node has not yet been retrieved. " | ||||
"Please call retrieve_parents() before using this property." | "Please call retrieve_parents() before using this property." | ||||
) | ) | ||||
return (x for x in self._parents_entries) | return (x for x in self._parents_entries) | ||||
def __str__(self): | def __str__(self): | ||||
return ( | return f"<MRevision[{self.id.hex()}]>" | ||||
f"<MRevision[{self.id.hex()}] " | |||||
f"date={self.date.isoformat()}, root={self.root.hex()}>" | def __eq__(self, other): | ||||
vlorentz: shouldn't it raise an exception or return `NotImplemented` if the other object is not a… | |||||
Done Inline ActionsWe should probably just force other to have type RevisionEntry with a proper annotation. The same applies for the other implementations of __eq__ in this module. I've just copied the way it was done in other swh modules but this clearly can be improved aeviso: We should probably just force `other` to have type `RevisionEntry` with a proper annotation. | |||||
Done Inline ActionsWell generally in Python, == between "incompatible types" just returns False douardda: Well generally in Python, `==` between "incompatible types" just returns `False` | |||||
) | return isinstance(other, RevisionEntry) and self.id == other.id | ||||
def __hash__(self): | |||||
return hash(self.id) | |||||
class DirectoryEntry: | class DirectoryEntry: | ||||
def __init__(self, id: Sha1Git, name: bytes = b""): | def __init__(self, id: Sha1Git, name: bytes = b""): | ||||
self.id = id | self.id = id | ||||
self.name = name | self.name = name | ||||
self._files: Optional[List[FileEntry]] = None | self._files: Optional[List[FileEntry]] = None | ||||
self._dirs: Optional[List[DirectoryEntry]] = None | self._dirs: Optional[List[DirectoryEntry]] = None | ||||
▲ Show 20 Lines • Show All 60 Lines • Show Last 20 Lines |
shouldn't it raise an exception or return NotImplemented if the other object is not a RevisionEntry object?