Skip to content

Commit 3fc6cdb

Browse files
feat: Drop Python 3.9 support, require Python 3.10+ (#2692)
* feat: Enhance JSON Schema support with prefixItems and tuple validation examples * docs: update CLI reference documentation 🤖 Generated by GitHub Actions * feat: Refactor type checks to use match-case syntax for improved readability * refactor: Simplify type check handling by removing redundant case statement * docs: update CLI reference documentation 🤖 Generated by GitHub Actions * refactor: update type alias import to use standard typing module * docs: update CLI reference documentation 🤖 Generated by GitHub Actions * docs: reorder "See also" sections for clarity in model and template customization * docs: update CLI reference documentation 🤖 Generated by GitHub Actions * fix: update CLI option from --target-python to --target-python-version for consistency * docs: update CLI reference documentation 🤖 Generated by GitHub Actions --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent b9131be commit 3fc6cdb

90 files changed

Lines changed: 451 additions & 1562 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
strategy:
2222
fail-fast: false
2323
matrix:
24-
py: ["3.14", "3.13", "3.12", "3.11", "3.10", "3.9"]
24+
py: ["3.14", "3.13", "3.12", "3.11", "3.10"]
2525
os: [ubuntu-24.04, windows-latest, macos-latest]
2626
tox_env: ['']
2727
include:

docs/cli-reference/field-customization.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ providing fine-grained control over generated names independent of schema defini
3939
!!! tip "Usage"
4040

4141
```bash
42-
datamodel-codegen --input schema.json --aliases openapi/aliases.json --target-python 3.9 # (1)!
42+
datamodel-codegen --input schema.json --aliases openapi/aliases.json --target-python-version 3.10 # (1)!
4343
```
4444

4545
1. :material-arrow-left: `--aliases` - the option documented here
@@ -317,10 +317,9 @@ providing fine-grained control over generated names independent of schema defini
317317
318318
from __future__ import annotations
319319
320-
from typing import Annotated, List, Union
320+
from typing import Annotated, List, TypeAlias, Union
321321
322322
from msgspec import UNSET, Meta, Struct, UnsetType, field
323-
from typing_extensions import TypeAlias
324323
325324
326325
class Pet(Struct):
@@ -803,10 +802,9 @@ store fields not defined in the schema. Options: allow, ignore, forbid.
803802

804803
from __future__ import annotations
805804

806-
from typing import List, Literal, Optional
805+
from typing import List, Literal, Optional, TypeAlias
807806

808807
from pydantic import BaseModel, Extra, Field
809-
from typing_extensions import TypeAlias
810808

811809
Boolean: TypeAlias = bool
812810
"""
@@ -2803,10 +2801,9 @@ generated models, preserving documentation from the original schema.
28032801
28042802
from __future__ import annotations
28052803
2806-
from typing import Annotated, Any, List, Optional, Union
2804+
from typing import Annotated, Any, List, Optional, TypeAlias, Union
28072805
28082806
from pydantic import BaseModel, Field
2809-
from typing_extensions import TypeAlias
28102807
28112808
Model: TypeAlias = Any
28122809

docs/cli-reference/model-customization.md

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,9 +1584,7 @@ control over dataclass generation.
15841584
from __future__ import annotations
15851585

15861586
from dataclasses import dataclass
1587-
from typing import List, Literal, Optional
1588-
1589-
from typing_extensions import TypeAlias
1587+
from typing import List, Literal, Optional, TypeAlias
15901588

15911589
Boolean: TypeAlias = bool
15921590
"""
@@ -3339,10 +3337,9 @@ for the generated code. Supported values include `pydantic.BaseModel`,
33393337
33403338
from __future__ import annotations
33413339
3342-
from typing import List, Literal, Optional
3340+
from typing import List, Literal, Optional, TypeAlias
33433341
33443342
from pydantic import BaseModel, Field
3345-
from typing_extensions import TypeAlias
33463343
33473344
Boolean: TypeAlias = bool
33483345
"""
@@ -3504,9 +3501,7 @@ for the generated code. Supported values include `pydantic.BaseModel`,
35043501
from __future__ import annotations
35053502
35063503
from dataclasses import dataclass
3507-
from typing import List, Literal, Optional
3508-
3509-
from typing_extensions import TypeAlias
3504+
from typing import List, Literal, Optional, TypeAlias
35103505
35113506
Boolean: TypeAlias = bool
35123507
"""
@@ -4626,8 +4621,8 @@ Target Python version for generated code syntax and imports.
46264621

46274622
The `--target-python-version` flag controls Python version-specific syntax:
46284623

4629-
- **Python 3.9**: Uses `Optional[X]` for optional types, `typing.Dict/List`
4630-
- **Python 3.10+**: Can use `X | None` union operator, built-in `dict/list`
4624+
- **Python 3.10-3.11**: Uses `X | None` union operator, `TypeAlias` annotation
4625+
- **Python 3.12+**: Uses `type` statement for type aliases
46314626

46324627
This affects import statements and type annotation syntax in generated code.
46334628

@@ -4636,7 +4631,7 @@ This affects import statements and type annotation syntax in generated code.
46364631
!!! tip "Usage"
46374632

46384633
```bash
4639-
datamodel-codegen --input schema.json --target-python-version 3.9 --use-standard-collections # (1)!
4634+
datamodel-codegen --input schema.json --target-python-version 3.10 --use-standard-collections # (1)!
46404635
```
46414636

46424637
1. :material-arrow-left: `--target-python-version` - the option documented here
@@ -4676,7 +4671,7 @@ This affects import statements and type annotation syntax in generated code.
46764671

46774672
**Output:**
46784673

4679-
=== "Python 3.9"
4674+
=== "Python 3.10"
46804675

46814676
```python
46824677
# generated by datamodel-codegen:
@@ -4700,30 +4695,6 @@ This affects import statements and type annotation syntax in generated code.
47004695
comment: None = None
47014696
```
47024697

4703-
=== "Python 3.10"
4704-
4705-
```python
4706-
# generated by datamodel-codegen:
4707-
# filename: person.json
4708-
# timestamp: 2019-07-26T00:00:00+00:00
4709-
4710-
from __future__ import annotations
4711-
4712-
from typing import Any
4713-
4714-
from pydantic import BaseModel, Field, conint
4715-
4716-
4717-
class Person(BaseModel):
4718-
firstName: str | None = Field(None, description="The person's first name.")
4719-
lastName: str | None = Field(None, description="The person's last name.")
4720-
age: conint(ge=0) | None = Field(
4721-
None, description='Age in years which must be equal to or greater than zero.'
4722-
)
4723-
friends: list[Any] | None = None
4724-
comment: None = None
4725-
```
4726-
47274698
---
47284699

47294700
## `--union-mode` {#union-mode}
@@ -4938,10 +4909,9 @@ default values.
49384909

49394910
from __future__ import annotations
49404911

4941-
from typing import List, Literal, Optional
4912+
from typing import List, Literal, Optional, TypeAlias
49424913

49434914
from pydantic import BaseModel, Field
4944-
from typing_extensions import TypeAlias
49454915

49464916
Boolean: TypeAlias = bool
49474917
"""
@@ -5551,8 +5521,7 @@ type, providing better type safety and IDE support.
55515521
from __future__ import annotations
55525522

55535523
from enum import Enum
5554-
5555-
from typing_extensions import TypeAlias
5524+
from typing import TypeAlias
55565525

55575526
Boolean: TypeAlias = bool
55585527
"""

docs/cli-reference/template-customization.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ is useful when using custom types defined in external modules (e.g.,
6969
from __future__ import annotations
7070

7171
from datetime import date, datetime
72-
from typing import Literal, Optional
72+
from typing import Literal, Optional, TypeAlias
7373

7474
from mymodule.myclass import MyCustomPythonClass
7575
from pydantic import BaseModel, Field
76-
from typing_extensions import TypeAlias
7776

7877
Boolean: TypeAlias = bool
7978
"""
@@ -511,10 +510,9 @@ formatting rules beyond what black/isort provide.
511510
# a comment
512511
from __future__ import annotations
513512

514-
from typing import Literal, Optional
513+
from typing import Literal, Optional, TypeAlias
515514

516515
from pydantic import BaseModel, Field
517-
from typing_extensions import TypeAlias
518516

519517
Boolean: TypeAlias = bool
520518
"""

docs/cli-reference/typing-customization.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,10 +1113,9 @@ of Enum classes for all enumerations.
11131113
11141114
from __future__ import annotations
11151115
1116-
from typing import Literal
1116+
from typing import Literal, TypeAlias
11171117
11181118
from pydantic import BaseModel
1119-
from typing_extensions import TypeAlias
11201119
11211120
Boolean: TypeAlias = bool
11221121
"""
@@ -1156,8 +1155,7 @@ of Enum classes for all enumerations.
11561155
from __future__ import annotations
11571156
11581157
from enum import Enum
1159-
1160-
from typing_extensions import TypeAlias
1158+
from typing import TypeAlias
11611159
11621160
Boolean: TypeAlias = bool
11631161
"""
@@ -1244,8 +1242,9 @@ defined enum members.
12441242
12451243
from __future__ import annotations
12461244
1245+
from typing import TypeAlias
1246+
12471247
from pydantic import BaseModel
1248-
from typing_extensions import TypeAlias
12491248
12501249
Boolean: TypeAlias = bool
12511250
"""
@@ -1285,8 +1284,7 @@ defined enum members.
12851284
from __future__ import annotations
12861285
12871286
from enum import Enum
1288-
1289-
from typing_extensions import TypeAlias
1287+
from typing import TypeAlias
12901288
12911289
Boolean: TypeAlias = bool
12921290
"""
@@ -2699,7 +2697,7 @@ Use built-in dict/list instead of typing.Dict/List.
26992697

27002698
The `--use-standard-collections` flag generates built-in container types
27012699
(dict, list) instead of typing module equivalents. This produces cleaner
2702-
code for Python 3.9+ where built-in types support subscripting.
2700+
code for Python 3.10+ where built-in types support subscripting.
27032701

27042702
**Related:** [`--use-generic-container-types`](typing-customization.md#use-generic-container-types)
27052703

@@ -2908,7 +2906,7 @@ code for Python 3.9+ where built-in types support subscripting.
29082906
Use TypeAlias instead of root models for type definitions (experimental).
29092907

29102908
The `--use-type-alias` flag generates TypeAlias declarations instead of
2911-
root model classes for certain type definitions. For Python 3.9-3.11, it
2909+
root model classes for certain type definitions. For Python 3.10-3.11, it
29122910
generates TypeAliasType, and for Python 3.12+, it uses the 'type' statement
29132911
syntax. This feature is experimental.
29142912

@@ -2975,10 +2973,9 @@ syntax. This feature is experimental.
29752973
29762974
from __future__ import annotations
29772975
2978-
from typing import Annotated, Any, List, Optional, Union
2976+
from typing import Annotated, Any, List, Optional, TypeAlias, Union
29792977
29802978
from pydantic import BaseModel, Field
2981-
from typing_extensions import TypeAlias
29822979
29832980
Model: TypeAlias = Any
29842981
@@ -3040,10 +3037,9 @@ syntax. This feature is experimental.
30403037
30413038
from __future__ import annotations
30423039
3043-
from typing import Literal, Optional, Union
3040+
from typing import Literal, Optional, TypeAlias, Union
30443041
30453042
from pydantic import BaseModel, Field
3046-
from typing_extensions import TypeAlias
30473043
30483044
Boolean: TypeAlias = bool
30493045
"""

docs/pyproject_toml.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ You can define multiple named profiles for different use cases within a single p
2323

2424
```toml
2525
[tool.datamodel-codegen]
26-
target-python-version = "3.9"
26+
target-python-version = "3.10"
2727
snake-case-field = true
2828

2929
[tool.datamodel-codegen.profiles.api]

0 commit comments

Comments
 (0)