Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
FIX - Add 3.14 annotation support for signature construction
  • Loading branch information
kapilreddy committed Nov 4, 2025
commit 249fadfe8398e28289a38a6786067b74b70ef55a
25 changes: 24 additions & 1 deletion dspy/signatures/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,30 @@ def __new__(mcs, signature_name, bases, namespace, **kwargs):
# At this point, the orders have been swapped already.
field_order = [name for name, value in namespace.items() if isinstance(value, FieldInfo)]
# Set `str` as the default type for all fields
raw_annotations = namespace.get("__annotations__", {})
if sys.version_info >= (3, 14):
try:
import annotationlib
# Try to get from explicit __annotations__ first (e.g., from __future__ import annotations)
raw_annotations = namespace.get("__annotations__")

if raw_annotations is None:
# In 3.14 with PEP 649, get the annotate function and call it
annotate_func = annotationlib.get_annotate_from_class_namespace(namespace)
if annotate_func:
raw_annotations = annotationlib.call_annotate_function(
annotate_func,
format=annotationlib.Format.FORWARDREF
)
else:
raw_annotations = {}
except ImportError:
raw_annotations = namespace.get("__annotations__", {})
# Safely get annotations using inspect module
else:
# Python 3.13 and earlier
# Set `str` as the default type for all fields
raw_annotations = namespace.get("__annotations__", {})

for name, field in namespace.items():
if not isinstance(field, FieldInfo):
continue # Don't add types to non-field attributes
Expand Down
Loading