Custom data typesΒΆ

To create your own data type, inherit a new class from Field

Note

Implement the generate() method if you use the Length validator along with your data type

Note

Implement the get_step() method if you use the Range validator along with your data type

Note

Implement the get_other_value() methods if you use the Equal, OneOf, NoneOf validator along with your data type

Example:

from sgen import fields


class MyInt(fields.Field)

    def set_positive_values(self):
        self._register(1)  # Add a valid type value

    def set_negative_values(self):
        self._register('not_int')  # Add a value that is not an instance of your data type

    def get_other_value(self, value: int) -> int:
        if value is None:
            return 1
        return value + 1

    def __add__():
        pass

    def __sub__():
        pass