Skip to content

Commit 0de0e5e

Browse files
committed
fix: Deactivate Pydantic validation on Python 3.9 is eval-type-backport is not available (for modern typing syntax support)
Issue-241: #241
1 parent e74ecbf commit 0de0e5e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/mkdocstrings_handlers/python/config.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77
from dataclasses import field, fields
88
from typing import TYPE_CHECKING, Annotated, Any, Literal
99

10+
from mkdocstrings.loggers import get_logger
11+
1012
# YORE: EOL 3.10: Replace block with line 2.
1113
if sys.version_info >= (3, 11):
1214
from typing import Self
1315
else:
1416
from typing_extensions import Self
1517

18+
19+
logger = get_logger(__name__)
20+
21+
1622
try:
1723
# When Pydantic is available, use it to validate options (done automatically).
1824
# Users can therefore opt into validation by installing Pydantic in development/CI.
@@ -30,6 +36,17 @@
3036
if getattr(pydantic, "__version__", "1.").startswith("1."):
3137
raise ImportError # noqa: TRY301
3238

39+
if sys.version_info < (3, 10):
40+
try:
41+
import eval_type_backport # noqa: F401
42+
except ImportError:
43+
logger.debug(
44+
"Pydantic needs the `eval-type-backport` package to be installed "
45+
"for modern type syntax to work on Python 3.9. "
46+
"Deactivating Pydantic validation for Python handler options.",
47+
)
48+
raise
49+
3350
from inspect import cleandoc
3451

3552
from pydantic import Field as BaseField

0 commit comments

Comments
 (0)