Skip to content

Commit

Permalink
fix: Deactivate Pydantic validation on Python 3.9 is `eval-type-backp…
Browse files Browse the repository at this point in the history
…ort` is not available (for modern typing syntax support)

Issue-241: #241
  • Loading branch information
pawamoy committed Feb 4, 2025
1 parent e74ecbf commit 0de0e5e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/mkdocstrings_handlers/python/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@
from dataclasses import field, fields
from typing import TYPE_CHECKING, Annotated, Any, Literal

from mkdocstrings.loggers import get_logger

# YORE: EOL 3.10: Replace block with line 2.
if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self


logger = get_logger(__name__)


try:
# When Pydantic is available, use it to validate options (done automatically).
# Users can therefore opt into validation by installing Pydantic in development/CI.
Expand All @@ -30,6 +36,17 @@
if getattr(pydantic, "__version__", "1.").startswith("1."):
raise ImportError # noqa: TRY301

if sys.version_info < (3, 10):
try:
import eval_type_backport # noqa: F401
except ImportError:
logger.debug(
"Pydantic needs the `eval-type-backport` package to be installed "
"for modern type syntax to work on Python 3.9. "
"Deactivating Pydantic validation for Python handler options.",
)
raise

from inspect import cleandoc

from pydantic import Field as BaseField
Expand Down

0 comments on commit 0de0e5e

Please # to comment.