Skip to content

Documentation example has wrong number of arguments in validation method #456

@rgerkin

Description

@rgerkin

In cerberus 1.2, the example for http://docs.python-cerberus.org/en/stable/customize.html#custom-validators seems to have the wrong number of arguments. I was only able to get this to work with 2 arguments (including self), not 3. For example:

import quantities as pq
from cerberus import Validator

class MyValidator(Validator):  
    def _validate_type_seconds(self, value):
        if not isinstance(value, pq.quantity.Quantity):
            self._error('%s' % value, "Must be a Python quantity")
        if not value.simplified.units == pq.s:
            self._error('%s' % value, "Must have units of seconds")
        return True
        
schema = {'amount': {'type': 'seconds'}}
v = MyValidator(schema)
assert v.validate({'amount': 10*pq.s}) is True
assert v.validate({'amount': 10*pq.mV}) is False

Note that def _validate_type_seconds(self, value) has only self and value, whereas the documentation example has self, field, and value.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions