Jump to solution
Verify

The Fix

pip install pydantic==2.8.0

Based on closed pydantic/pydantic issue #9536 · PR/commit linked

Jump to Verify Open PR/Commit
@@ -307,6 +307,7 @@ def get_function_type_hints( globalns = add_module_globals(function) type_hints = {} + type_params: tuple[Any] = getattr(function, '__type_params__', ()) # type: ignore for name, value in annotations.items(): if include_keys is not None and name not in include_keys:
repro.py
from __future__ import annotations import typing import pydantic @pydantic.validate_call def max[T](args: typing.Iterable[T]) -> T: return sorted(args, reverse=True)[0] print(max([1,2, 10, 5]))
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\npip install pydantic==2.8.0\nWhen NOT to use: Do not use this fix if your code does not utilize generics with future annotations.\n\n

Why This Fix Works in Production

  • Trigger: C:\code\venv\Scripts\python.exe C:\code\devtools\foo.py
  • Mechanism: The error occurs due to missing type parameters when using generics with future annotations
  • Why the fix works: `validate_call` type params fix addressing NameError when using generics. (first fixed release: 2.8.0).

Why This Breaks in Prod

  • Shows up under Python 3.12 in real deployments (not just unit tests).
  • The error occurs due to missing type parameters when using generics with future annotations
  • Surfaces as: C:\code\venv\Scripts\python.exe C:\code\devtools\foo.py

Proof / Evidence

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“This is not uniquely a pydantic problem, and it's not related to eval_type_backport: The good news is that this was fixed in https://github.com/python/cpython/pull/118009 (which apparently…”
@alexmojaki · 2024-06-03 · confirmation · source
“@hb2638, Thanks for reporting this issue. @alexmojaki, any idea what's going on here?”
@sydney-runkle · 2024-06-03 · source
“OK, _eval_type was thankfully made backward-compatible in https://github.com/python/cpython/issues/118418”
@alexmojaki · 2024-06-03 · source
“> eval_type_backport (primarily the pydantic _typing_extras function, but also eventually the package) should start accepting type_params and passing it to _eval_type”
@alexmojaki · 2024-06-24 · source

Failure Signature (Search String)

  • C:\code\venv\Scripts\python.exe C:\code\devtools\foo.py

Error Message

Stack trace
error.txt
Error Message ------------- C:\code\venv\Scripts\python.exe C:\code\devtools\foo.py Traceback (most recent call last): File "C:\code\devtools\foo.py", line 8, in <module> @pydantic.validate_call ^^^^^^^^^^^^^^^^^^^^^^ File "C:\code\venv\Lib\site-packages\pydantic\validate_call_decorator.py", line 66, in validate_call return validate(func) ^^^^^^^^^^^^^^ File "C:\code\venv\Lib\site-packages\pydantic\validate_call_decorator.py", line 55, in validate validate_call_wrapper = _validate_call.ValidateCallWrapper(function, config, validate_return) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\code\venv\Lib\site-packages\pydantic\_internal\_validate_call.py", line 42, in __init__ schema = gen_schema.clean_schema(gen_schema.generate_schema(function)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\code\venv\Lib\site-packages\pydantic\_internal\_generate_schema.py", line 502, in generate_schema schema = self._generate_schema_inner(obj) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\code\venv\Lib\site-packages\pydantic\_internal\_generate_schema.py", line 758, in _generate_schema_inner return self.match_type(obj) ^^^^^^^^^^^^^^^^^^^^ File "C:\code\venv\Lib\site-packages\pydantic\_internal\_generate_schema.py", line 825, in match_type return self. ... (truncated) ...
Stack trace
error.txt
Error Message ------------- Traceback (most recent call last): File "test.py", line 7, in <module> print(typing.get_type_hints(foo)) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "typing.py", line 2281, in get_type_hints hints[name] = _eval_type(value, globalns, localns) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "typing.py", line 414, in _eval_type return t._evaluate(globalns, localns, recursive_guard) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "typing.py", line 924, in _evaluate eval(self.__forward_code__, globalns, localns), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<string>", line 1, in <module> NameError: name 'T' is not defined
Stack trace
error.txt
Error Message ------------- Traceback (most recent call last): File "/Users/alex/work/pydantic/pydantic/_internal/_generate_schema.py", line 695, in _resolve_forward_ref obj = _typing_extra.eval_type_backport(obj, globalns=self._types_namespace) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/alex/work/pydantic/pydantic/_internal/_typing_extra.py", line 262, in eval_type_backport return typing._eval_type( # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/alex/.pyenv/versions/3.12.4/lib/python3.12/typing.py", line 415, in _eval_type return t._evaluate(globalns, localns, type_params, recursive_guard=recursive_guard) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/alex/.pyenv/versions/3.12.4/lib/python3.12/typing.py", line 938, in _evaluate eval(self.__forward_code__, globalns, locals_to_pass), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<string>", line 1, in <module> NameError: name 'T' is not defined The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/Users/alex/Library/Application Support/JetBrains/PyCharm2024.1/scratches/scratch_26.py", line 6, in <module> @pydantic.validate_call(validate_return=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/alex/wo ... (truncated) ...

Minimal Reproduction

repro.py
from __future__ import annotations import typing import pydantic @pydantic.validate_call def max[T](args: typing.Iterable[T]) -> T: return sorted(args, reverse=True)[0] print(max([1,2, 10, 5]))

Environment

  • Python: 3.12
  • Pydantic: 2

What Broke

Users experience NameError when calling generic functions with future annotations.

Why It Broke

The error occurs due to missing type parameters when using generics with future annotations

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install pydantic==2.8.0

When NOT to use: Do not use this fix if your code does not utilize generics with future annotations.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/pydantic/pydantic/pull/9760

First fixed release: 2.8.0

Last verified: 2026-02-09. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not use this fix if your code does not utilize generics with future annotations.

Verify Fix

verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.

Did This Fix Work in Your Case?

Quick signal helps us prioritize which fixes to verify and improve.

Prevention

  • Add a CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
  • Upgrade behind a canary and run integration tests against the canary before 100% rollout.

Version Compatibility Table

VersionStatus
2.8.0 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.