Skip to content

Allowing serialized Settings in get_settings #688

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

Merged
merged 2 commits into from
Nov 15, 2024

Conversation

jamesbraza
Copy link
Collaborator

This allows me to use this function with config files

@jamesbraza jamesbraza added the enhancement New feature or request label Nov 15, 2024
@jamesbraza jamesbraza self-assigned this Nov 15, 2024
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Nov 15, 2024
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 15, 2024


def get_settings(config_or_name: MaybeSettings = None) -> Settings:
if isinstance(config_or_name, Settings):
return config_or_name
if isinstance(config_or_name, dict):
return Settings(**config_or_name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit but I'm more partial to .model_validate

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright moved to it 👌

Out of curiosity, why do you prefer model_validate here? I was playing around, and couldn't actually find a place where Settings(**config_or_name) validation fails while Settings.model_validate(config_or_name) succeeds

@jamesbraza jamesbraza force-pushed the supporting-dict-settings branch from b43ebe0 to 6a6d273 Compare November 15, 2024 18:07
@jamesbraza jamesbraza merged commit 2cc0a6a into main Nov 15, 2024
5 checks passed
@jamesbraza jamesbraza deleted the supporting-dict-settings branch November 15, 2024 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants