From e00b1a128c73ca7d414618430c032f07f59932b6 Mon Sep 17 00:00:00 2001 From: candifloss Date: Fri, 28 Feb 2025 01:12:18 +0530 Subject: [PATCH] Refactoring --- definitions/attribute.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/definitions/attribute.py b/definitions/attribute.py index 7163a07..098b028 100644 --- a/definitions/attribute.py +++ b/definitions/attribute.py @@ -69,7 +69,8 @@ class textAttribute(Attribute): return f"Max length must be greater than min length for '{self.attrib_name}'." if self.default_val is not None: if self.regex is not None: - if not re.match(self.regex, str(self.default_val)): + compiled_regex = re.compile(self.regex) + if not compiled_regex.match(str(self.default_val)): return f"Default value for '{self.attrib_name}' must match the pattern: {self.regex}" if self.allowed_chars is not None: for char in self.default_val: @@ -116,8 +117,10 @@ class intAttribute(Attribute): return f"Step must be an integer for attribute '{self.attrib_name}'." if self.step <= 0: return f"Step must be a positive integer for attribute '{self.attrib_name}'." - if self.min_val is not None and self.max_val is not None and self.step > (self.max_val - self.min_val): - return f"Step value is too large for attribute '{self.attrib_name}'." + if self.min_val is not None and self.max_val is not None: + range_val = self.max_val - self.min_val + if self.step > range_val: + return f"Step value is too large for attribute '{self.attrib_name}'." if self.default_val is not None: if not isinstance(self.default_val, int): return f"default_val must be an integer for attribute '{self.attrib_name}'." @@ -160,8 +163,10 @@ class floatAttribute(Attribute): return f"Step must be an float for attribute '{self.attrib_name}'." if self.step <= 0: return f"Step must be a positive float for attribute '{self.attrib_name}'." - if self.min_val is not None and self.max_val is not None and self.step > (self.max_val - self.min_val): - return f"Step value is too large for attribute '{self.attrib_name}'." + if self.min_val is not None and self.max_val is not None: + range_val = self.max_val - self.min_val + if self.step > range_val: + return f"Step value is too large for attribute '{self.attrib_name}'." if self.default_val is not None: if not isinstance(self.default_val, float): return f"default_val must be a number for attribute '{self.attrib_name}'."