Changed to StrEnum, which avoids the need for multiple inheritance (str, Enum) and makes the intent clearer
This commit is contained in:
@@ -197,11 +197,11 @@ Pydantic has a rich set of features to validate and transform data.
|
|||||||
In addition to standard features like required and optional fields with default values,
|
In addition to standard features like required and optional fields with default values,
|
||||||
Pydantic has built-in data processing tools like regex validation, enums, string manipulation, email validation, and more.
|
Pydantic has built-in data processing tools like regex validation, enums, string manipulation, email validation, and more.
|
||||||
```python
|
```python
|
||||||
from enum import Enum
|
from enum import StrEnum
|
||||||
from pydantic import AnyUrl, BaseModel, EmailStr, Field
|
from pydantic import AnyUrl, BaseModel, EmailStr, Field
|
||||||
|
|
||||||
|
|
||||||
class MusicBand(str, Enum):
|
class MusicBand(StrEnum):
|
||||||
AEROSMITH = "AEROSMITH"
|
AEROSMITH = "AEROSMITH"
|
||||||
QUEEN = "QUEEN"
|
QUEEN = "QUEEN"
|
||||||
ACDC = "AC/DC"
|
ACDC = "AC/DC"
|
||||||
|
|||||||
Reference in New Issue
Block a user