Skip to content
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

Allow disabling loading field from certain sources via annotation #521

Open
jvllmr opened this issue Jan 11, 2025 · 0 comments
Open

Allow disabling loading field from certain sources via annotation #521

jvllmr opened this issue Jan 11, 2025 · 0 comments
Assignees

Comments

@jvllmr
Copy link
Contributor

jvllmr commented Jan 11, 2025

In one of my newer projects I plan to use pydantic-settings paired with pydanclick for a declarative way to load settings from cli args and other sources such as pyproject.toml at the same time.

When thinking about it I noticed there could be cases where I don't want users to configure things from a specific source. For instance a --clean or --clear for creating a clean build in a build tool should only be possible via cli args in my opinion. Taking in this arg from other sources could lead to potentially destructive behaviour.

I think using an annotation would be the best way to implement this. I imagined it as something like this:

from pydantic_settings import BaseSettings, SettingsFieldOpts
from typing import Annotated

class BuildCmdSettings(BaseSettings):
    clean: Annotated[bool, SettingsFieldOpts(disable_sources=["PyprojectTomlConfigSettingsSource"])] = False

SettingsFieldOpts would be a new type which could hold more options for a field if needed in the future.

@jvllmr jvllmr changed the title Disable loading field from certain sources via annotation Allow disabling loading field from certain sources via annotation Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants