Skip to content

Commit c784c4b

Browse files
authored
Add Python 3.13 deprecation warning documentation (#2743)
* Add Python 3.13 deprecation warning documentation * Address review comments: add code block language and clarify filterwarnings
1 parent b186e30 commit c784c4b

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

docs/cli-reference/typing-customization.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,13 @@ The --disable-future-imports option stops the generator from adding
664664
you need compatibility with tools or environments that don't support
665665
postponed evaluation of annotations (PEP 563).
666666

667+
**Python 3.13+ Deprecation Warning:** When using `from __future__ import annotations`
668+
with older versions of Pydantic v1 (before 1.10.18), Python 3.13 may raise
669+
deprecation warnings related to `typing._eval_type()`. To avoid these warnings:
670+
671+
- Upgrade to Pydantic v1 >= 1.10.18 or Pydantic v2 (recommended)
672+
- Use this `--disable-future-imports` flag as a workaround
673+
667674
**See also:** [Python Version Compatibility](../python-version-compatibility.md)
668675

669676
!!! tip "Usage"

docs/python-version-compatibility.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,44 @@ This can happen when `__future__.annotations` interacts poorly with Pydantic's t
309309

310310
**Solution:** Try `--disable-future-imports` or update to Pydantic v2.
311311

312+
### Python 3.13 DeprecationWarning with `typing._eval_type`
313+
314+
When running on Python 3.13+ with `from __future__ import annotations`, you may see:
315+
316+
```text
317+
DeprecationWarning: Failing to pass a value to the 'type_params' parameter
318+
of 'typing._eval_type' is deprecated...
319+
```
320+
321+
This occurs because Python 3.13 deprecated calling `typing._eval_type()` without the `type_params` parameter. Libraries that evaluate forward references (like older Pydantic versions) trigger this warning.
322+
323+
**Solutions:**
324+
325+
1. **Upgrade Pydantic** (recommended):
326+
- Pydantic v1: Upgrade to version 1.10.18 or later
327+
- Pydantic v2: Upgrade to the latest version
328+
329+
2. **Use `--disable-future-imports`** as a workaround:
330+
```bash
331+
datamodel-codegen --input schema.json --output models.py --disable-future-imports
332+
```
333+
334+
3. **Suppress the warning** in pytest (temporary fix):
335+
```toml
336+
# pyproject.toml
337+
[tool.pytest.ini_options]
338+
filterwarnings = [
339+
# For Pydantic v2's v1 compatibility layer (pydantic.v1)
340+
"ignore::DeprecationWarning:pydantic.v1.typing",
341+
# For standalone Pydantic v1
342+
"ignore::DeprecationWarning:pydantic.typing",
343+
]
344+
```
345+
346+
!!! note
347+
Python 3.14+ will use native deferred annotations (PEP 649), and the generator
348+
will no longer add `from __future__ import annotations` for those versions.
349+
312350
### IDE shows type errors
313351

314352
Some IDEs don't fully understand `from __future__ import annotations`.

tests/main/jsonschema/test_main_jsonschema.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ def test_main_keep_model_order_field_references(output_file: Path) -> None:
137137
'from __future__ import annotations' to the output. This is useful when
138138
you need compatibility with tools or environments that don't support
139139
postponed evaluation of annotations (PEP 563).
140+
141+
**Python 3.13+ Deprecation Warning:** When using `from __future__ import annotations`
142+
with older versions of Pydantic v1 (before 1.10.18), Python 3.13 may raise
143+
deprecation warnings related to `typing._eval_type()`. To avoid these warnings:
144+
145+
- Upgrade to Pydantic v1 >= 1.10.18 or Pydantic v2 (recommended)
146+
- Use this `--disable-future-imports` flag as a workaround
140147
"""
141148
run_main_and_assert(
142149
input_path=JSON_SCHEMA_DATA_PATH / "keep_model_order_field_references.json",

0 commit comments

Comments
 (0)