From f2512ded4a8f41e0d17b583d289ad31ba0a5e6e1 Mon Sep 17 00:00:00 2001 From: squidfunk Date: Wed, 30 Aug 2023 16:06:27 +0200 Subject: [PATCH] Fixed blog plugin compatibility with Python < 3.9 --- material/plugins/blog/structure/options.py | 14 +++++++------- src/plugins/blog/structure/options.py | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/material/plugins/blog/structure/options.py b/material/plugins/blog/structure/options.py index d37779185..281dec9fb 100644 --- a/material/plugins/blog/structure/options.py +++ b/material/plugins/blog/structure/options.py @@ -18,28 +18,28 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. -from collections import UserDict from datetime import date, datetime, time from mkdocs.config.base import BaseConfigOption, Config, ValidationError +from typing import Dict # ----------------------------------------------------------------------------- # Classes # ----------------------------------------------------------------------------- # Date dictionary -class DateDict(UserDict[str, datetime]): +class DateDict(Dict[str, datetime]): # Initialize date dictionary def __init__(self, data: dict): super().__init__(data) - # Initialize date of creation - if "created" in data: - self.created: datetime = data["created"] + # Ensure presence of `date.created` + self.created: datetime = data["created"] + # Allow attribute access def __getattr__(self, name: str): - if name in self.data: - return self.data[name] + if name in self: + return self[name] # ----------------------------------------------------------------------------- diff --git a/src/plugins/blog/structure/options.py b/src/plugins/blog/structure/options.py index d37779185..281dec9fb 100644 --- a/src/plugins/blog/structure/options.py +++ b/src/plugins/blog/structure/options.py @@ -18,28 +18,28 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. -from collections import UserDict from datetime import date, datetime, time from mkdocs.config.base import BaseConfigOption, Config, ValidationError +from typing import Dict # ----------------------------------------------------------------------------- # Classes # ----------------------------------------------------------------------------- # Date dictionary -class DateDict(UserDict[str, datetime]): +class DateDict(Dict[str, datetime]): # Initialize date dictionary def __init__(self, data: dict): super().__init__(data) - # Initialize date of creation - if "created" in data: - self.created: datetime = data["created"] + # Ensure presence of `date.created` + self.created: datetime = data["created"] + # Allow attribute access def __getattr__(self, name: str): - if name in self.data: - return self.data[name] + if name in self: + return self[name] # -----------------------------------------------------------------------------