make config class a better interface
This commit is contained in:
parent
66b597d90c
commit
426e5a7d66
2 changed files with 14 additions and 15 deletions
|
@ -3,7 +3,20 @@ from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
pass
|
def merge_with(self, other, strict: bool = False):
|
||||||
|
"""
|
||||||
|
Merges the other config into this one
|
||||||
|
:param other:
|
||||||
|
:param strict: whether conflicting options are allowed or not
|
||||||
|
:return: self
|
||||||
|
"""
|
||||||
|
for var in vars(self):
|
||||||
|
if not getattr(self, var):
|
||||||
|
setattr(self, var, getattr(other, var))
|
||||||
|
else:
|
||||||
|
if strict and getattr(other, var) is not None and getattr(self, var) != getattr(other, var):
|
||||||
|
raise NotImplementedError
|
||||||
|
return self
|
||||||
|
|
||||||
|
|
||||||
class FormatterIF:
|
class FormatterIF:
|
||||||
|
|
|
@ -53,20 +53,6 @@ class FormattingConfig(Config):
|
||||||
def from_yaml(cls, yaml):
|
def from_yaml(cls, yaml):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def merge_with(self, other, strict: bool = False):
|
|
||||||
"""
|
|
||||||
Merges the other config into this one
|
|
||||||
:param other:
|
|
||||||
:param strict: whether conflicting options are allowed or not
|
|
||||||
:return: self
|
|
||||||
"""
|
|
||||||
for var in vars(self):
|
|
||||||
if not getattr(self, var):
|
|
||||||
setattr(self, var, getattr(other, var))
|
|
||||||
else:
|
|
||||||
if strict and getattr(other, var) is not None and getattr(self, var) != getattr(other, var):
|
|
||||||
raise NotImplementedError
|
|
||||||
return self
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def naming_scheme(self) -> NamingScheme:
|
def naming_scheme(self) -> NamingScheme:
|
||||||
|
|
Loading…
Reference in a new issue