Skip to content

Commit f2512de

Browse files
committed
Fixed blog plugin compatibility with Python < 3.9
1 parent 4c6b004 commit f2512de

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

material/plugins/blog/structure/options.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,28 @@
1818
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
1919
# IN THE SOFTWARE.
2020

21-
from collections import UserDict
2221
from datetime import date, datetime, time
2322
from mkdocs.config.base import BaseConfigOption, Config, ValidationError
23+
from typing import Dict
2424

2525
# -----------------------------------------------------------------------------
2626
# Classes
2727
# -----------------------------------------------------------------------------
2828

2929
# Date dictionary
30-
class DateDict(UserDict[str, datetime]):
30+
class DateDict(Dict[str, datetime]):
3131

3232
# Initialize date dictionary
3333
def __init__(self, data: dict):
3434
super().__init__(data)
3535

36-
# Initialize date of creation
37-
if "created" in data:
38-
self.created: datetime = data["created"]
36+
# Ensure presence of `date.created`
37+
self.created: datetime = data["created"]
3938

39+
# Allow attribute access
4040
def __getattr__(self, name: str):
41-
if name in self.data:
42-
return self.data[name]
41+
if name in self:
42+
return self[name]
4343

4444
# -----------------------------------------------------------------------------
4545

src/plugins/blog/structure/options.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,28 @@
1818
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
1919
# IN THE SOFTWARE.
2020

21-
from collections import UserDict
2221
from datetime import date, datetime, time
2322
from mkdocs.config.base import BaseConfigOption, Config, ValidationError
23+
from typing import Dict
2424

2525
# -----------------------------------------------------------------------------
2626
# Classes
2727
# -----------------------------------------------------------------------------
2828

2929
# Date dictionary
30-
class DateDict(UserDict[str, datetime]):
30+
class DateDict(Dict[str, datetime]):
3131

3232
# Initialize date dictionary
3333
def __init__(self, data: dict):
3434
super().__init__(data)
3535

36-
# Initialize date of creation
37-
if "created" in data:
38-
self.created: datetime = data["created"]
36+
# Ensure presence of `date.created`
37+
self.created: datetime = data["created"]
3938

39+
# Allow attribute access
4040
def __getattr__(self, name: str):
41-
if name in self.data:
42-
return self.data[name]
41+
if name in self:
42+
return self[name]
4343

4444
# -----------------------------------------------------------------------------
4545

0 commit comments

Comments
 (0)