You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The convention with BL_Python's ConfigBuilder is that any config classes must end with Config, however, the way this is enforced allows for any text following the ending Config. This is problematic mainly because the portion of the config name preceding Config is used as the attribute name in the generated config type, and is also the expected key for a loaded TOML file (when using load_config). As such, this may lead to surprising or confusing behavior if someone were to use a class name with text following Config in a class name.
Working reproduction:
importBL_Python.programming.configasconfigfrompydanticimportBaseModelclassConfig(BaseModel, config.AbstractConfig):
passclassMyFooConfigExtra(BaseModel):
# `my_foo` should end up as `Foo` by defaultmy_foo: str="Foo"config_type=config.ConfigBuilder()\
.with_root_config(Config)\
.with_configs([MyFooConfigExtra])\
.build()
loaded_config=config.load_config(config_type, 'config.toml')
print(loaded_config)
Working config.
Script prints myfoo=MyFooConfigExtra(my_foo='Bar')
[myfoo]
# `myfoo` gets set to the config value `Bar`, which is correct.my_foo = 'Bar'
Example of possibly confusing config. This does not work.
Same result when using the key myfooconfigextra.
Script prints myfoo=None
[myfooextra]
# `myfoo` is not set to the config value `Bar` and ends up as `None`. This is not correct.my_foo = 'Bar'
Note that in this failure case, it would not be expected for the ConfigBuilder to find this section because there is no MyFooExtraConfig passed to with_configs(...). So, in that sense, myfoo being None is "correct." The issue is that this is confusing to users of ConfigBuilder because the word "extra" is not correct to use, but seems like it should be used.
The text was updated successfully, but these errors were encountered:
The convention with BL_Python's
ConfigBuilder
is that any config classes must end withConfig
, however, the way this is enforced allows for any text following the endingConfig
. This is problematic mainly because the portion of the config name precedingConfig
is used as the attribute name in the generated config type, and is also the expected key for a loaded TOML file (when usingload_config
). As such, this may lead to surprising or confusing behavior if someone were to use a class name with text followingConfig
in a class name.Working reproduction:
Working config.
Script prints
myfoo=MyFooConfigExtra(my_foo='Bar')
Example of possibly confusing config. This does not work.
Same result when using the key
myfooconfigextra
.Script prints
myfoo=None
Note that in this failure case, it would not be expected for the
ConfigBuilder
to find this section because there is noMyFooExtraConfig
passed towith_configs(...)
. So, in that sense,myfoo
beingNone
is "correct." The issue is that this is confusing to users ofConfigBuilder
because the word "extra" is not correct to use, but seems like it should be used.The text was updated successfully, but these errors were encountered: