-
-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix PathType typing in case of sequence #402
Conversation
31bd350
to
8b97867
Compare
I just fixed the syntax error to let the CI run |
Perfect thank you so much, I amended without staging the changes and after that I didn't have my laptop on hand 😅 |
bbf5846
to
252729d
Compare
252729d
to
bdc05e6
Compare
I fixed the CI, there were still a couple of unused imports. It should be good to merge :) |
Thanks @just-maiyak for updating this PR. Could you provide a simple example that has mypy error? I am going to test the error and the fix? Thanks! |
Sure, if you run mypy on this file : from pydantic_settings import BaseSettings, YamlConfigSettingsSource
class Settings(BaseSettings):
config_files = ["config.yaml"]
model_config = YamlConfigSettingsSource(BaseSettings, yaml_file=config_files) It will fail with the error I reported in #401. |
Thanks @just-maiyak for providing the example. The model that you provided looks weird to me. Could you explain why you are using |
I'm trying to read settings from a list of yaml files (just like we would from a .env file). I'm following the docs right here : Other Settings Source. |
But this should be like the first example in the page: from typing import Tuple, Type
from pydantic import BaseModel
from pydantic_settings import (
BaseSettings,
PydanticBaseSettingsSource,
SettingsConfigDict,
TomlConfigSettingsSource,
)
class Nested(BaseModel):
nested_field: str
class Settings(BaseSettings):
foobar: str
nested: Nested
model_config = SettingsConfigDict(toml_file='config.toml')
@classmethod
def settings_customise_sources(
cls,
settings_cls: Type[BaseSettings],
init_settings: PydanticBaseSettingsSource,
env_settings: PydanticBaseSettingsSource,
dotenv_settings: PydanticBaseSettingsSource,
file_secret_settings: PydanticBaseSettingsSource,
) -> Tuple[PydanticBaseSettingsSource, ...]:
return (TomlConfigSettingsSource(settings_cls),) You only need to change the |
Alright, it's not very clear from the docs that you have to keep |
This is because yaml settings source is not part of the default settings sources and you need to somehow override the default behavior to enable this source. we decided to use this approach to prevent breaking change in V2. BTW, any improvement on docs is welcome. feel free to create a PR if you want. You don't need to create a new issue. Thanks! |
I'll work on a docs contribution :) Thanks for helping out ! |
Sorry for being so persistent ... I'm reopening this again because I still thing the issue is happening in the case I start from the sample you provide and parametrize the from typing import Tuple, Type
from pydantic import BaseModel
from pydantic_settings import (
BaseSettings,
PydanticBaseSettingsSource,
SettingsConfigDict,
TomlConfigSettingsSource,
)
class Nested(BaseModel):
nested_field: str
class Settings(BaseSettings):
foobar: str
nested: Nested
config_files: list[str] = ["config.yaml"] # This might be the return of a funtion or initialized in __init__
model_config = SettingsConfigDict(toml_file=config_files)
@classmethod
def settings_customise_sources(
cls,
settings_cls: Type[BaseSettings],
init_settings: PydanticBaseSettingsSource,
env_settings: PydanticBaseSettingsSource,
dotenv_settings: PydanticBaseSettingsSource,
file_secret_settings: PydanticBaseSettingsSource,
) -> Tuple[PydanticBaseSettingsSource, ...]:
return (TomlConfigSettingsSource(settings_cls),) This produces yet again the same error as before. Should this be done in another way ? |
I think the There is an issue for this problem #259 |
That's my case indeed, want to provide additional files at runtime. Unfortunately, I still have the same typing problem even with the workaround as soon as I wrap the settings filenames in a I still think the What also works is to explicitly type whatever we're passing as |
Fixes #401