diff options
Diffstat (limited to 'plugins/UM3NetworkPrinting/src/Models/BaseModel.py')
-rw-r--r-- | plugins/UM3NetworkPrinting/src/Models/BaseModel.py | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/plugins/UM3NetworkPrinting/src/Models/BaseModel.py b/plugins/UM3NetworkPrinting/src/Models/BaseModel.py index 3d38a4b116..92d7246489 100644 --- a/plugins/UM3NetworkPrinting/src/Models/BaseModel.py +++ b/plugins/UM3NetworkPrinting/src/Models/BaseModel.py @@ -18,45 +18,56 @@ class BaseModel: def validate(self) -> None: pass - ## Checks whether the two models are equal. - # \param other: The other model. - # \return True if they are equal, False if they are different. def __eq__(self, other): + """Checks whether the two models are equal. + + :param other: The other model. + :return: True if they are equal, False if they are different. + """ return type(self) == type(other) and self.toDict() == other.toDict() - ## Checks whether the two models are different. - # \param other: The other model. - # \return True if they are different, False if they are the same. def __ne__(self, other) -> bool: + """Checks whether the two models are different. + + :param other: The other model. + :return: True if they are different, False if they are the same. + """ return type(self) != type(other) or self.toDict() != other.toDict() - ## Converts the model into a serializable dictionary def toDict(self) -> Dict[str, Any]: + """Converts the model into a serializable dictionary""" + return self.__dict__ - ## Parses a single model. - # \param model_class: The model class. - # \param values: The value of the model, which is usually a dictionary, but may also be already parsed. - # \return An instance of the model_class given. @staticmethod def parseModel(model_class: Type[T], values: Union[T, Dict[str, Any]]) -> T: + """Parses a single model. + + :param model_class: The model class. + :param values: The value of the model, which is usually a dictionary, but may also be already parsed. + :return: An instance of the model_class given. + """ if isinstance(values, dict): return model_class(**values) return values - ## Parses a list of models. - # \param model_class: The model class. - # \param values: The value of the list. Each value is usually a dictionary, but may also be already parsed. - # \return A list of instances of the model_class given. @classmethod def parseModels(cls, model_class: Type[T], values: List[Union[T, Dict[str, Any]]]) -> List[T]: + """Parses a list of models. + + :param model_class: The model class. + :param values: The value of the list. Each value is usually a dictionary, but may also be already parsed. + :return: A list of instances of the model_class given. + """ return [cls.parseModel(model_class, value) for value in values] - ## Parses the given date string. - # \param date: The date to parse. - # \return The parsed date. @staticmethod def parseDate(date: Union[str, datetime]) -> datetime: + """Parses the given date string. + + :param date: The date to parse. + :return: The parsed date. + """ if isinstance(date, datetime): return date return datetime.strptime(date, "%Y-%m-%dT%H:%M:%S.%fZ").replace(tzinfo=timezone.utc) |