Skip to content

Commit e423286

Browse files
committed
Partial fix for Python 3.14.
1 parent 6c1af33 commit e423286

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

django_pydantic_field/v2/utils.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@
99
if ty.TYPE_CHECKING:
1010
from collections.abc import Mapping
1111

12+
try:
13+
from annotationlib import get_annotations # Python >= 3.14
14+
except ImportError:
1215

13-
def get_annotated_type(obj, field, default=None) -> ty.Any:
14-
try:
16+
def get_annotations(obj):
1517
if isinstance(obj, type):
16-
annotations = obj.__dict__["__annotations__"]
18+
return obj.__dict__["__annotations__"]
1719
else:
18-
annotations = obj.__annotations__
20+
return obj.__annotations__
21+
22+
23+
def get_annotated_type(obj, field, default=None) -> ty.Any:
24+
try:
25+
annotations = get_annotations(obj)
1926

2027
return annotations[field]
2128
except (AttributeError, KeyError):

0 commit comments

Comments
 (0)