-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X
Description
Bug
Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":
pydantic version: 1.6.1
pydantic compiled: True
install path: <path-to-virtualenv>/lib/python3.8/site-packages/pydantic
python version: 3.8.1 (default, Dec 29 2019, 16:51:17) [GCC 9.2.0]
platform: Linux-5.7.2-arch1-1-x86_64-with-glibc2.29
optional deps. installed: ['typing-extensions']
When combining enum values with a Literal typing the use_enum_values config is not respected:
from enum import Enum
from typing import Literal
from pydantic import BaseModel
class FruitEnum(Enum):
pear = 'pear'
banana = 'banana'
class CookingModel(BaseModel):
fruit: FruitEnum
class Config:
use_enum_values = True
class LiteralCookingModel(BaseModel):
fruit: Literal[FruitEnum.pear]
class Config:
use_enum_values = True
cm = CookingModel(fruit=FruitEnum.pear)
print(cm.dict())
# outputs: {'fruit': 'pear'}
lcm = LiteralCookingModel(fruit=FruitEnum.pear)
print(lcm.dict())
# outputs: {'fruit': <FruitEnum.pear: 'pear'>}awemulya, DrPyser and rentzhx3
Metadata
Metadata
Assignees
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X