def check_rules(self) -> YieldFlake8Error: """Check missing lines.""" expected = OrderedSet(self._expected_lines()) actual = OrderedSet(self.file_path.read_text().split("\n")) missing = expected - actual if missing: yield self.flake8_error(2, " has missing lines:", "\n".join(sorted(missing)))
def field2choices(self, field, **kwargs): """Return the dictionary of OpenAPI field attributes for valid choices definition :param Field field: A marshmallow field. :rtype: dict """ attributes = {} comparable = [ validator.comparable for validator in field.validators if hasattr(validator, "comparable") ] if comparable: attributes["enum"] = comparable else: choices = [ OrderedSet(validator.choices) for validator in field.validators if hasattr(validator, "choices") ] if choices: attributes["enum"] = list(functools.reduce(operator.and_, choices)) return attributes
def field2choices(self, field, **kwargs): """Return the dictionary of OpenAPI field attributes for valid choices definition :param Field field: A marshmallow field. :rtype: dict @TODO Work out if we're going to need this at all for Schematics. """ attributes = {} vals = [] if hasattr(field, 'validators'): vals = field.validators comparable = [ validator.comparable for validator in vals if hasattr(validator, "comparable") ] if comparable: attributes["enum"] = comparable else: choices = [ OrderedSet(validator.choices) for validator in vals if hasattr(validator, "choices") ] if choices: attributes["enum"] = list( functools.reduce(operator.and_, choices)) return attributes
def field2choices(field): """Return the set of valid choices for a :class:`Field <marshmallow.fields.Field>`, or ``None`` if no choices are specified. :param Field field: A marshmallow field. :rtype: set """ validators = [ OrderedSet(validator.choices) for validator in field.validators if hasattr(validator, 'choices') ] return (functools.reduce(operator.and_, validators) if validators else None)
def __to_choices(self): attributes = {} comparable = [ validator.comparable for validator in self._validators if hasattr(validator, 'comparable') ] if comparable: attributes['enum'] = comparable else: choices = [ OrderedSet(validator.choices) for validator in self._validators if hasattr(validator, 'choices') ] if choices: attributes['enum'] = list( functools.reduce(operator.and_, choices)) return attributes
def field2choices(field): """Return the set of valid choices for a :class:`Field <marshmallow.fields.Field>`, or ``None`` if no choices are specified. :param Field field: A marshmallow field. :rtype: set """ comparable = { validator.comparable for validator in field.validators if hasattr(validator, 'comparable') } if comparable: return comparable choices = [ OrderedSet(validator.choices) for validator in field.validators if hasattr(validator, 'choices') ] if choices: return functools.reduce(operator.and_, choices)