Skip to content

Conversation

Viicos
Copy link

@Viicos Viicos commented Oct 18, 2025

Motivation and Context

This is a first step in adding support for Pydantic 2.12 and Python 3.14. It avoids relying on patterns that we discourage using in Pydantic (mostly around the FieldInfo class), and removes usage of private utilities.

How Has This Been Tested?

Breaking Changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Comment on lines +36 to +37
"typing-extensions>=4.9.0",
"typing-inspection>=0.4.1",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typing-extensions is already used in the project, but not declared as an explicit dependency. 4.9.0 is the oldest version with (proper) support for typing_extensions.deprecated.

typing-inspection is already a Pydantic dependency, so nothing new added here.

if type_hints:
# Classes with type hints can be converted to Pydantic models
model = _create_model_from_class(type_annotation)
model = _create_model_from_class(type_annotation, type_hints)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_create_model_from_class() used to compute the type hints again, pass them to avoid unnecessarily computing them again.

Comment on lines -471 to -513
def _get_typed_signature(call: Callable[..., Any]) -> inspect.Signature:
"""Get function signature while evaluating forward references"""
signature = inspect.signature(call)
globalns = getattr(call, "__globals__", {})
typed_params = [
inspect.Parameter(
name=param.name,
kind=param.kind,
default=param.default,
annotation=_get_typed_annotation(param.annotation, globalns),
)
for param in signature.parameters.values()
]
typed_return = _get_typed_annotation(signature.return_annotation, globalns)
typed_signature = inspect.Signature(typed_params, return_annotation=typed_return)
return typed_signature
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed, we can just use inspect.get_annotations() with eval_str=True.

It also enables more use cases to be supported, e.g.:

from __future__ import annotations

def func[T](a: T): ...

from_metadata(func)  # Used to raise

Let me know if I should add a test for this.

Kludex
Kludex previously approved these changes Oct 22, 2025
Copy link
Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR keeps the support for Pydantic 2.11.

@Viicos is maintaining Pydantic, so he knows stuff.

@Viicos Viicos force-pushed the refactor-func-metadata branch from 5dff9fa to cf3ae5c Compare October 22, 2025 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants