obj.__dict__ calls → obj.serialized or vars(obj)
This commit is contained in:
parent
9220a75980
commit
6ec193d554
2
TODO.md
2
TODO.md
|
@ -1,6 +1,4 @@
|
|||
- Refactoring
|
||||
- filter string serialize thing
|
||||
- `x.__dict__` → `vars(x)`
|
||||
- Make all icon SVG files white/black, since we can now use ColorOverlay
|
||||
- Make the icon blue in EditAccount when hovering and no avatar set
|
||||
|
||||
|
|
|
@ -318,7 +318,7 @@ class MatrixClient(nio.AsyncClient):
|
|||
room = self.models[Room, self.user_id][room_id]
|
||||
|
||||
if room.last_event is None:
|
||||
room.last_event = item.__dict__
|
||||
room.last_event = item.serialized
|
||||
return
|
||||
|
||||
for_us = item.target_id in self.backend.clients
|
||||
|
@ -334,7 +334,7 @@ class MatrixClient(nio.AsyncClient):
|
|||
if item.date < room.last_event["date"]: # If this is a past event
|
||||
return
|
||||
|
||||
room.last_event = item.__dict__
|
||||
room.last_event = item.serialized
|
||||
|
||||
|
||||
async def register_nio_room(self, room: nio.MatrixRoom, left: bool = False,
|
||||
|
@ -492,7 +492,7 @@ class MatrixClient(nio.AsyncClient):
|
|||
async def onErrorResponse(self, resp: nio.ErrorResponse) -> None:
|
||||
# TODO: show something in the client, must be seen on login screen too
|
||||
try:
|
||||
log.warning("%s - %s", resp, json.dumps(resp.__dict__, indent=4))
|
||||
log.warning("%s - %s", resp, json.dumps(vars(resp), indent=4))
|
||||
except Exception:
|
||||
log.warning(repr(resp))
|
||||
|
||||
|
@ -549,7 +549,7 @@ class MatrixClient(nio.AsyncClient):
|
|||
else:
|
||||
to = "???"
|
||||
log.warning("Invalid visibility - %s",
|
||||
json.dumps(ev.__dict__, indent=4))
|
||||
json.dumps(vars(ev), indent=4))
|
||||
|
||||
co = f"%1 made future room history visible to {to}."
|
||||
await self.register_nio_event(room, ev, content=co)
|
||||
|
@ -642,7 +642,7 @@ class MatrixClient(nio.AsyncClient):
|
|||
)
|
||||
|
||||
log.warning("Invalid member event - %s",
|
||||
json.dumps(ev.__dict__, indent=4))
|
||||
json.dumps(vars(ev), indent=4))
|
||||
return None
|
||||
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class Room(ModelItem):
|
|||
left: bool = False
|
||||
typing_members: List[str] = field(default_factory=list)
|
||||
|
||||
# Event __dict__
|
||||
# Event.serialized
|
||||
last_event: Optional[Dict[str, Any]] = field(default=None, repr=False)
|
||||
|
||||
def __lt__(self, other: "Room") -> bool:
|
||||
|
|
|
@ -54,8 +54,8 @@ class Model(MutableMapping):
|
|||
new = value
|
||||
|
||||
if key in self:
|
||||
existing = dict(self[key].__dict__) # copy to not alter with pop
|
||||
merged = {**existing, **value.__dict__}
|
||||
existing = dict(self[key].serialized) # copy to not alter with pop
|
||||
merged = {**existing, **value.serialized}
|
||||
|
||||
existing.pop("parent_model", None)
|
||||
merged.pop("parent_model", None)
|
||||
|
@ -63,7 +63,9 @@ class Model(MutableMapping):
|
|||
if merged == existing:
|
||||
return
|
||||
|
||||
new = type(value)(**merged)
|
||||
merged_init_kwargs = {**vars(self[key]), **vars(value)}
|
||||
merged_init_kwargs.pop("parent_model", None)
|
||||
new = type(value)(**merged_init_kwargs)
|
||||
|
||||
new.parent_model = self
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user