Open acederberg opened 1 month ago
Hello @acederberg, Thanks for reporting this issue.
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 the settings_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 using super.
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.
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?
No, there is no clear way to do this. any improvement PR is welcome but it shouldn't introduce a new breaking change
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?