pattern: Fix and improve config overriding in from_configfile method
Fix error when a configuration value loaded from a config file is also given as keyword parameter to the from_configfile method. Override configuration loaded from config file only if the provided value is not None.
This commit is contained in:
parent
a41c03e4c8
commit
9fd91f007d
2 changed files with 28 additions and 3 deletions
|
@ -251,13 +251,15 @@ class Lister(Generic[StateType, PageType]):
|
|||
@classmethod
|
||||
def from_configfile(cls, **kwargs: Any):
|
||||
"""Instantiate a lister from the configuration loaded from the
|
||||
SWH_CONFIG_FILENAME envvar, with potential extra keyword arguments.
|
||||
SWH_CONFIG_FILENAME envvar, with potential extra keyword arguments
|
||||
if their value is not None.
|
||||
|
||||
Args:
|
||||
kwargs: kwargs passed to the lister instantiation
|
||||
"""
|
||||
config = load_from_envvar()
|
||||
return cls.from_config(**config, **kwargs)
|
||||
config = dict(load_from_envvar())
|
||||
config.update({k: v for k, v in kwargs.items() if v is not None})
|
||||
return cls.from_config(**config)
|
||||
|
||||
|
||||
class StatelessLister(Lister[None, PageType], Generic[PageType]):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue