mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-13 22:54:27 -04:00
working runtime type casting and enforcement for a wide range of types
This commit is contained in:
parent
0d8a076c1f
commit
ab09560f14
3 changed files with 162 additions and 61 deletions
|
@ -39,15 +39,24 @@ class Link:
|
|||
tags: Optional[str]
|
||||
sources: List[str]
|
||||
history: Dict[str, List[ArchiveResult]] = field(default_factory=lambda: {})
|
||||
updated: Optional[str] = None
|
||||
updated: Optional[datetime] = None
|
||||
|
||||
def __hash__(self):
|
||||
return self.urlhash
|
||||
def __post_init__(self):
|
||||
"""fix any history result items to be type-checked ArchiveResults"""
|
||||
cast_history = {}
|
||||
for method, method_history in self.history.items():
|
||||
cast_history[method] = []
|
||||
for result in method_history:
|
||||
if isinstance(result, dict):
|
||||
result = ArchiveResult(**result)
|
||||
cast_history[method].append(result)
|
||||
|
||||
object.__setattr__(self, 'history', cast_history)
|
||||
|
||||
def __eq__(self, other):
|
||||
if not isinstance(other, Link):
|
||||
return NotImplemented
|
||||
return self.urlhash == other.urlhash
|
||||
return self.url == other.url
|
||||
|
||||
def __gt__(self, other):
|
||||
if not isinstance(other, Link):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue