-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
More __init__
Overwrite Support
#346
Comments
Hello @acederberg,
I agree, it is confusing and you have to do a lot of work which is not good. unfortunately, we can't change it in V2, because it will introduce a breaking change but we will improve it in V3 for sure to make it clear and easy.
No, there is no clear way to do this. any improvement PR is welcome but it shouldn't introduce a new breaking change |
Made an issue on the ``pydantic/pydantic_settings`` github to see if I could make this work the way I'd like. See pydantic/pydantic-settings#346.
Hi @hramezani! Changes should be in #350. I went with a callback pattern, as it would appear to be the least intrusive. I do not think it has any breaking changes. |
Hello Everybody!
My apologies if this is a bit long.
The problem
Support for passing additional overwriting keyword arguments for additional sources to
__init__
is confusing. I would like to overwrite some values in one of my sources, but it looks like I'd have to create my source in thesettings_customize_sources
classmethod to get it into_settings_build_values
, which means I'd have to overwrite the_settings_build_values
method somehow. This is less than desirable, since I have no means to inject those sources usingsuper
.My Use Case
I have a bit of an odd use case for a library I'm writing. This library supports loading
YAML
from many sources optionally with reloading of the files or not when creating new instances. I know that there is aYAML
source defined here, but my use case is different enough that I want to write my own source.Essentially, I want to inject sources on an instance level when overwrites (
_yaml_files
and_yaml_settings
) are provided, otherwise it uses the source created with the subclass hook:The main problem is that
_settings_build_values
uses the source customization hooksettings_customize_sources
which is aclassmethod
- there is no means to pass instance data to the hook.I don't want to copy and paste the definition of
_settings_build_values
from here and maintain it in my library, that is not an elegant or easy to maintain solution. I also want to keep all of the functionality ofBaseSettings
without overwriting signatures ideally. I would like to do something likeand have
sources_extra
concatenation to the localsources
.Is there an obvious way to do this I am not noticing? Should I just give up and not use
BaseSettings
and write an equivalent? If not, should I make a pull request doing roughly that which is specified in the block of code here?The text was updated successfully, but these errors were encountered: