Code: Use vars() instead of directly accessing __dict__
This commit is contained in:
parent
509d33e1b7
commit
b60062d455
|
@ -83,7 +83,7 @@ class GameMetadataView(QTreeView, SideTabContents):
|
||||||
self.set_title.emit(self.rgame.app_title)
|
self.set_title.emit(self.rgame.app_title)
|
||||||
self.model.clear()
|
self.model.clear()
|
||||||
try:
|
try:
|
||||||
self.model.load(view.__dict__)
|
self.model.load(vars(view))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
self.resizeColumnToContents(0)
|
self.resizeColumnToContents(0)
|
||||||
|
|
|
@ -198,7 +198,7 @@ class RareLauncher(RareApp):
|
||||||
|
|
||||||
def send_message(self, message: BaseModel):
|
def send_message(self, message: BaseModel):
|
||||||
if self.socket:
|
if self.socket:
|
||||||
self.socket.write(json.dumps(message.__dict__).encode("utf-8"))
|
self.socket.write(json.dumps(vars(message)).encode("utf-8"))
|
||||||
self.socket.flush()
|
self.socket.flush()
|
||||||
else:
|
else:
|
||||||
self.logger.error("Can't send message")
|
self.logger.error("Can't send message")
|
||||||
|
|
|
@ -42,7 +42,7 @@ class InstallOptionsModel:
|
||||||
def as_install_kwargs(self) -> Dict:
|
def as_install_kwargs(self) -> Dict:
|
||||||
return {
|
return {
|
||||||
k: getattr(self, k)
|
k: getattr(self, k)
|
||||||
for k in self.__dict__
|
for k in vars(self)
|
||||||
if k not in ["update", "silent", "create_shortcut", "overlay", "install_prereqs"]
|
if k not in ["update", "silent", "create_shortcut", "overlay", "install_prereqs"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from typing import Dict
|
||||||
|
|
||||||
|
|
||||||
class Actions:
|
class Actions:
|
||||||
|
@ -15,7 +16,7 @@ class BaseModel:
|
||||||
app_name: str
|
app_name: str
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, data: dict):
|
def from_json(cls, data: Dict):
|
||||||
return cls(
|
return cls(
|
||||||
action=data["action"],
|
action=data["action"],
|
||||||
app_name=data["app_name"]
|
app_name=data["app_name"]
|
||||||
|
@ -28,9 +29,9 @@ class FinishedModel(BaseModel):
|
||||||
playtime: int # seconds
|
playtime: int # seconds
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, data):
|
def from_json(cls, data: Dict):
|
||||||
return cls(
|
return cls(
|
||||||
**BaseModel.from_json(data).__dict__,
|
**vars(BaseModel.from_json(data)),
|
||||||
exit_code=data["exit_code"],
|
exit_code=data["exit_code"],
|
||||||
playtime=data["playtime"],
|
playtime=data["playtime"],
|
||||||
)
|
)
|
||||||
|
@ -47,7 +48,7 @@ class StateChangedModel(BaseModel):
|
||||||
new_state: int
|
new_state: int
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, data):
|
def from_json(cls, data: Dict):
|
||||||
return cls(
|
return cls(
|
||||||
action=data["action"],
|
action=data["action"],
|
||||||
app_name=data["app_name"],
|
app_name=data["app_name"],
|
||||||
|
@ -60,8 +61,8 @@ class ErrorModel(BaseModel):
|
||||||
error_string: str
|
error_string: str
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, data):
|
def from_json(cls, data: Dict):
|
||||||
return cls(
|
return cls(
|
||||||
**BaseModel.from_json(data).__dict__,
|
**vars(BaseModel.from_json(data)),
|
||||||
error_string=data["error_string"]
|
error_string=data["error_string"]
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue