From 426e5a7d66e7e1805a15770c4ca2900a29375c1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sun, 6 Feb 2022 21:26:55 +0100 Subject: [PATCH] make config class a better interface --- PyTeX/format/formatterif.py | 15 ++++++++++++++- PyTeX/format/formatting_config.py | 14 -------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/PyTeX/format/formatterif.py b/PyTeX/format/formatterif.py index 916fe28..f3ec29d 100644 --- a/PyTeX/format/formatterif.py +++ b/PyTeX/format/formatterif.py @@ -3,7 +3,20 @@ from pathlib import Path 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: diff --git a/PyTeX/format/formatting_config.py b/PyTeX/format/formatting_config.py index 704263d..c3ecc60 100644 --- a/PyTeX/format/formatting_config.py +++ b/PyTeX/format/formatting_config.py @@ -53,20 +53,6 @@ class FormattingConfig(Config): def from_yaml(cls, yaml): 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 def naming_scheme(self) -> NamingScheme: