Skip to content

Commit 619e18d

Browse files
committed
refactor: Support Jinja2 3.1
Issue #360: #360
1 parent f42dfc6 commit 619e18d

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/mkdocstrings/loggers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
from pathlib import Path
55
from typing import Any, Callable, Optional, Tuple
66

7-
from jinja2 import contextfunction
87
from jinja2.runtime import Context
98
from mkdocs.utils import warning_filter
109

10+
try:
11+
from jinja2 import pass_context
12+
except ImportError: # TODO: remove once Jinja2 < 3.1 is dropped
13+
from jinja2 import contextfunction as pass_context # noqa: WPS440
14+
1115
TEMPLATES_DIR = Path(__file__).parent / "templates"
1216

1317

@@ -71,7 +75,7 @@ def get_template_logger_function(logger_func: Callable) -> Callable:
7175
A function.
7276
"""
7377

74-
@contextfunction
78+
@pass_context
7579
def wrapper(context: Context, msg: Optional[str] = None) -> str:
7680
"""Log a message.
7781

0 commit comments

Comments
 (0)