Это то, что у меня было раньше
Код: Выделить всё
`my_list: list[str]`
Код: Выделить всё
MY_LIST=["a","b"]Код: Выделить всё
Input should be a valid list [type=list_type, input_value='["a","b"]', input_type=str]
For further information visit https://errors.pydantic.dev/2.6/v/list_type
Подводя итог, следующий код работает в версии 1.9
Код: Выделить всё
from pydantic import BaseSettings, Field
import os
import logging
import sys
class Settings(BaseSettings):
my_list: list[str] = Field(..., env="MY_LIST")
class Config:
env_file = f'{os.environ.get("ENV")}.env'
env_file_encoding = 'utf-8'
env_prefix = f'{os.environ.get("ENV")}_'
extra='ignore'
try:
settings = Settings()
print(settings)
except Exception as e:
logging.critical(f"required settings not provided, shutting down - {e}")
sys.exit(1)
Код: Выделить всё
result - my_list=['a', 'b']Код: Выделить всё
from pydantic import Field
from pydantic_settings import BaseSettings
import os
import logging
import sys
class Settings(BaseSettings):
my_list: list[str] = Field(..., env="MY_LIST")
class Config:
env_file = f'{os.environ.get("ENV")}.env'
env_file_encoding = 'utf-8'
env_prefix = f'{os.environ.get("ENV")}_'
extra='ignore'
try:
settings = Settings()
print(settings)
except Exception as e:
logging.critical(f"required settings not provided, shutting down - {e}")
sys.exit(1)
Код: Выделить всё
CRITICAL:root:required settings not provided, shutting down - 1 validation error for Settings
my_list
Input should be a valid list [type=list_type, input_value='["a","b"]', input_type=str]
For further information visit https://errors.pydantic.dev/2.6/v/list_type