Changeset View
Changeset View
Standalone View
Standalone View
swh/model/model.py
Show First 20 Lines • Show All 842 Lines • ▼ Show 20 Lines | class MetadataAuthority(BaseModel): | ||||
def to_dict(self): | def to_dict(self): | ||||
d = super().to_dict() | d = super().to_dict() | ||||
if d["metadata"] is None: | if d["metadata"] is None: | ||||
del d["metadata"] | del d["metadata"] | ||||
return d | return d | ||||
@classmethod | @classmethod | ||||
def from_dict(cls, d): | def from_dict(cls, d): | ||||
d["type"] = MetadataAuthorityType(d["type"]) | d = { | ||||
**d, | |||||
"type": MetadataAuthorityType(d["type"]), | |||||
} | |||||
return super().from_dict(d) | return super().from_dict(d) | ||||
vlorentz: for consistency with other `from_dict` methods:
```
d = d.copy()
d["type"] =… | |||||
def unique_key(self) -> KeyType: | def unique_key(self) -> KeyType: | ||||
return {"type": self.type.value, "url": self.url} | return {"type": self.type.value, "url": self.url} | ||||
@attr.s(frozen=True, slots=True) | @attr.s(frozen=True, slots=True) | ||||
class MetadataFetcher(BaseModel): | class MetadataFetcher(BaseModel): | ||||
"""Represents a software component used to fetch metadata from a metadata | """Represents a software component used to fetch metadata from a metadata | ||||
▲ Show 20 Lines • Show All 235 Lines • Show Last 20 Lines |
for consistency with other from_dict methods:
(mypy isn't smart enough to detect we're changing the type so it's fine)