def __init__(self, field, operator, value):
if not isinstance(operator, ConstraintOperator):<EOL><INDENT>operator = ConstraintOperator(operator)<EOL><DEDENT>if not isinstance(field, Field):<EOL><INDENT>field = Field(field)<EOL><DEDENT>self.field = field<EOL>self._op = operator<EOL>if self._op.is_inequality() and not isinstance(value, Number):<EOL><INDENT>raise ValueError('<STR_LIT>'.format(value))<EOL><DEDENT>elif self._op.is_type():<EOL><INDENT>value = value.lower()<EOL>t = self.TYPE_MAPPING.get(value, None)<EOL>if t is None:<EOL><INDENT>allowed = '<STR_LIT:U+002CU+0020>'.join(list(self.TYPE_MAPPING.keys()))<EOL>raise ValueError('<STR_LIT>'.format(value, allowed))<EOL><DEDENT>self._orig_value, value = value, t<EOL><DEDENT>elif self._op.is_regex():<EOL><INDENT>if isinstance(value, Number):<EOL><INDENT>raise ValueError('<STR_LIT>'.format(value))<EOL><DEDENT>self._orig_value, value = value, re.compile(value)<EOL><DEDENT>self.value = value<EOL>
Create constraint on a field.

        :param field: A constraint field
        :type field: Field or str
        :param operator: A constraint operator
        :type operator: ConstraintOperator or str
        :param value: Target value
        :type value: str, Number
        :raise: ValueError if operator/value combination is illegal, or if
                building a Field or ConstraintOperator instance fails.