From 5472cfdb538908038c2c46dd9700a53ca155fe45 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Mon, 22 Aug 2022 21:28:51 +0200 Subject: [PATCH] Refactor: move default.copy() logic to the BaseConfigOption class --- mkdocs/config/base.py | 12 ++++++++++++ mkdocs/config/config_options.py | 8 ++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/mkdocs/config/base.py b/mkdocs/config/base.py index c3b01e63..9a6099fa 100644 --- a/mkdocs/config/base.py +++ b/mkdocs/config/base.py @@ -17,6 +17,18 @@ class BaseConfigOption: self.warnings = [] self.default = None + @property + def default(self): + try: + # ensure no mutable values are assigned + return self._default.copy() + except AttributeError: + return self._default + + @default.setter + def default(self, value): + self._default = value + def validate(self, value): return self.run_validation(value) diff --git a/mkdocs/config/config_options.py b/mkdocs/config/config_options.py index 25499ac1..887ff693 100644 --- a/mkdocs/config/config_options.py +++ b/mkdocs/config/config_options.py @@ -69,13 +69,9 @@ class OptionallyRequired(BaseConfigOption): if value is None: if self.default is not None: - if hasattr(self.default, 'copy'): - # ensure no mutable values are assigned - value = self.default.copy() - else: - value = self.default + value = self.default elif not self.required: - return + return None elif self.required: raise ValidationError("Required configuration not provided.")