def normalize(self): if (self.tag is None or not isinstance(self.tag, str)): raise exceptions.DataRequirementsError( f"'{self.yaml_tag}' requires string for denoting type, " f"got: '{self.tag}' of type '{type(self.tag)}'", None, None) try: value = locate(self.tag) self.tag = value except Exception as err: raise exceptions.DataRequirementsError( f"'{self.yaml_tag}' could not determine type data from " f"'{self.tag}'.", err, None) from err
def normalize(self): if isinstance(self.tag, str): value = self.tag.lower() self.tag = value else: raise exceptions.DataRequirementsError( f"'{self.yaml_tag}' requires a string for denoting key name, " f"got: '{self.tag}' of type '{type(self.tag)}'", None, None)
def normalize(self): ''' Attempts to normalize self.tag, throws DataRequirementsError if it finds something invalid. ''' value = self.tag if value is None: raise exceptions.DataRequirementsError( f"'{self.yaml_tag}' requires a value, " f"got: '{self.tag}' of type '{type(self.tag)}'", None, None) if isinstance(value, str): value = value.lower() cast = None try: cast = int(value) except ValueError: pass if cast is not None: value = cast elif (value == 'positive' or value == '>'): value = 1 elif (value == 'non-negative' or value == '>='): value = 0 elif (value == 'any' or value == 'all' or value == '<'): value = -1 if isinstance(value, int): value = mathing.sign(value) else: raise exceptions.DataRequirementsError( f"'{self.yaml_tag}' requires: an integer or exactly " f"these strings: " f"'positive'/'>', " f"'non-negative'/'zero'/'>=', " f"or 'any'/'all'/'<'. " f"Got: '{value}' of type '{type(value)}'", None, None) # Ok... finally done; save our normalized value back to instance var. self.tag = value
def normalize(self): value = self.tag.lower() validated = None if value in self._VALUES_VALID: # Already a canonical name. validated = value else: # Look for a canonical name in the alternatives. for key in self._VALUES_VALID: alternatives = self._VALUES_VALID[key] if value in alternatives: validated = key break if validated: self.tag = validated else: raise exceptions.DataRequirementsError( f"'{self.yaml_tag}' requires one of these strings: " f"'repeat'/'repeating'. " f"Got: '{value}' of type '{type(value)}'", None, None)
def __init__(self, value): super().__init__(value) if self.tag == 0: self._valid_value_fn = int.__ge__ self._valid_comparison = 0 elif self.tag > 0: self._valid_value_fn = int.__gt__ self._valid_comparison = 0 elif self.tag < 0: self._valid_value_fn = int.__lt__ self._valid_comparison = 0 else: raise exceptions.DataRequirementsError( f"'{self.yaml_tag}' requires integer for comparison: " f"negative (e.g. -1) means less-than zero; " f"zero (e.g. 0) means greater-than-or-equal-to zero; " f"positive (e.g. 1) means greater-than zero. " f"got: '{value}' of type '{type(value)}'", None, None)
def __init__(self, value): super().__init__(value) if not self._valid_type(value): raise exceptions.DataRequirementsError( f"'{self.yaml_tag}' requires string type, " f"got: '{value}' of type '{type(value)}'", None, None)