MCPcopy Create free account
hub / github.com/tortoise/tortoise-orm / __init__

Method __init__

tortoise/fields/data.py:877–901  ·  view source on GitHub ↗
(
        self,
        enum_type: type[IntEnum],
        description: str | None = None,
        generated: bool = False,
        **kwargs: Any,
    )

Source from the content-addressed store, hash-verified

875
876class IntEnumFieldInstance(SmallIntField):
877 def __init__(
878 self,
879 enum_type: type[IntEnum],
880 description: str | None = None,
881 generated: bool = False,
882 **kwargs: Any,
883 ) -> None:
884 # Validate values
885 minimum = 1 if generated else -32768
886 for item in enum_type:
887 try:
888 value = int(item.value)
889 except ValueError:
890 raise ConfigurationError("IntEnumField only supports integer enums!")
891 if not minimum <= value < 32768:
892 raise ConfigurationError(
893 f"The valid range of IntEnumField's values is {minimum}..32767!"
894 )
895
896 # Automatic description for the field if not specified by the user
897 if description is None:
898 description = "\n".join([f"{e.name}: {int(e.value)}" for e in enum_type])[:2048]
899
900 super().__init__(description=description, **kwargs)
901 self.enum_type = enum_type
902
903 def to_python_value(self, value: int | None) -> IntEnum | None:
904 value = self.enum_type(value) if value is not None else None

Callers

nothing calls this directly

Calls 2

ConfigurationErrorClass · 0.90
__init__Method · 0.45

Tested by

no test coverage detected