Source code for package_name_to_import_with.utils

 1"""Define helper utilities."""
 2
 3import enum
 4
 5import pydantic
 6
 7
[docs] 8class CustomFloatEnum(float, enum.Enum): 9 """Inherit `enum.Enum` and modify behaviour of ``__str__``.""" 10 11 def __str__(self: "CustomFloatEnum") -> str: 12 """Create printable string representation using value instead of name. 13 14 Returns 15 ------- 16 str 17 value of the enum member 18 """ 19 return str(self.value)
20 21
[docs] 22class CustomStrEnum(str, enum.Enum): 23 """Inherit `enum.Enum` and modify behaviour of ``__str__``.""" 24 25 def __str__(self: "CustomStrEnum") -> str: 26 """Create printable string representation using value instead of name. 27 28 Returns 29 ------- 30 str 31 value of the enum member 32 """ 33 return str(self.value)
34 35
[docs] 36class CustomPydanticBaseModel(pydantic.BaseModel): 37 """Inherit `pydantic.BaseModel` and change behaviour to handle undefined attributes.""" 38 39 model_config = pydantic.ConfigDict(extra="forbid")
40 41 42__all__ = ["CustomFloatEnum", "CustomPydanticBaseModel", "CustomStrEnum"]