From da5683c876682019fe2360cf56fd27afe9f39844 Mon Sep 17 00:00:00 2001 From: ChrisTerBeke Date: Mon, 26 Nov 2018 15:30:30 +0100 Subject: [PATCH 1/2] add typing to models --- plugins/UM3NetworkPrinting/src/Models.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Models.py b/plugins/UM3NetworkPrinting/src/Models.py index d0708c8127..2a34e41f86 100644 --- a/plugins/UM3NetworkPrinting/src/Models.py +++ b/plugins/UM3NetworkPrinting/src/Models.py @@ -4,17 +4,17 @@ ## Base model that maps kwargs to instance attributes. class BaseModel: - def __init__(self, **kwargs): + def __init__(self, **kwargs) -> None: self.__dict__.update(kwargs) self.validate() - def validate(self): + def validate(self) -> None: pass ## Class representing a material that was fetched from the cluster API. class ClusterMaterial(BaseModel): - def __init__(self, **kwargs): + def __init__(self, **kwargs) -> None: self.guid = None # type: str self.material = None # type: str self.brand = None # type: str @@ -23,14 +23,14 @@ class ClusterMaterial(BaseModel): self.density = None # type: str super().__init__(**kwargs) - def validate(self): + def validate(self) -> None: if not self.guid: raise ValueError("guid is required on ClusterMaterial") ## Class representing a local material that was fetched from the container registry. class LocalMaterial(BaseModel): - def __init__(self, **kwargs): + def __init__(self, **kwargs) -> None: self.GUID = None # type: str self.id = None # type: str self.type = None # type: str @@ -49,7 +49,7 @@ class LocalMaterial(BaseModel): self.compatible = None # type: bool super().__init__(**kwargs) - def validate(self): + def validate(self) -> None: if not self.GUID: raise ValueError("guid is required on LocalMaterial") if not self.id: From e4d8fb36abccd5e1a5f7f68bef086ae82ec3b9a4 Mon Sep 17 00:00:00 2001 From: ChrisTerBeke Date: Mon, 26 Nov 2018 15:53:04 +0100 Subject: [PATCH 2/2] Add more typing as per request from @sedwards2009 --- plugins/UM3NetworkPrinting/src/Models.py | 35 ++++++++---------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Models.py b/plugins/UM3NetworkPrinting/src/Models.py index 2a34e41f86..5ef44bc006 100644 --- a/plugins/UM3NetworkPrinting/src/Models.py +++ b/plugins/UM3NetworkPrinting/src/Models.py @@ -14,43 +14,30 @@ class BaseModel: ## Class representing a material that was fetched from the cluster API. class ClusterMaterial(BaseModel): - def __init__(self, **kwargs) -> None: - self.guid = None # type: str - self.material = None # type: str - self.brand = None # type: str - self.version = None # type: int - self.color = None # type: str - self.density = None # type: str + def __init__(self, guid = str, version = str, **kwargs) -> None: + self.guid = guid # type: str + self.version = version # type: int super().__init__(**kwargs) def validate(self) -> None: if not self.guid: raise ValueError("guid is required on ClusterMaterial") + if not self.version: + raise ValueError("version is required on ClusterMaterial") ## Class representing a local material that was fetched from the container registry. class LocalMaterial(BaseModel): - def __init__(self, **kwargs) -> None: - self.GUID = None # type: str - self.id = None # type: str - self.type = None # type: str - self.status = None # type: str - self.base_file = None # type: str - self.setting_version = None # type: int - self.version = None # type: int - self.brand = None # type: str - self.material = None # type: str - self.color_name = None # type: str - self.color_code = None # type: str - self.description = None # type: str - self.adhesion_info = None # type: str - self.approximate_diameter = None # type: str - self.definition = None # type: str - self.compatible = None # type: bool + def __init__(self, GUID = str, id = str, version = str, **kwargs) -> None: + self.GUID = GUID # type: str + self.id = id # type: str + self.version = version # type: int super().__init__(**kwargs) def validate(self) -> None: if not self.GUID: raise ValueError("guid is required on LocalMaterial") + if not self.version: + raise ValueError("version is required on LocalMaterial") if not self.id: raise ValueError("id is required on LocalMaterial")