The Fix
pip install pydantic==2.8.0
Based on closed pydantic/pydantic issue #9536 · PR/commit linked
@@ -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:
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]))
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
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
- GitHub issue: #9536
- Fix PR: https://github.com/pydantic/pydantic/pull/9760
- First fixed release: 2.8.0
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.21
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…”
“@hb2638, Thanks for reporting this issue. @alexmojaki, any idea what's going on here?”
“OK, _eval_type was thankfully made backward-compatible in https://github.com/python/cpython/issues/118418”
“> 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”
Failure Signature (Search String)
- C:\code\venv\Scripts\python.exe C:\code\devtools\foo.py
Error Message
Stack trace
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 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 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
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
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.
When NOT to Use This Fix
- Do not use this fix if your code does not utilize generics with future annotations.
Verify Fix
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
| Version | Status |
|---|---|
| 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.