Describe the bug
The python target version argument seems to have no effect on using more modern typing from python
For example, targeting 3.11 will still give type that are written as List[int]
instead of the more modern list[int]
To Reproduce
Example schema:
openapi: 3.0.0
components:
schemas:
User:
type: object
properties:
names:
type: array
items:
type: string
Used command line:
$ datamodel-codegen --input specification.yml --target-python-version 3.11
The results is
# generated by datamodel-codegen:
# filename: specification.yml
# timestamp: 2023-08-30T20:49:24+00:00
from __future__ import annotations
from typing import List, Optional
from pydantic import BaseModel
class User(BaseModel):
names: Optional[List[str]] = None
Expected behavior
I'd expect that the newest feature of python would be used and the output would be
# generated by datamodel-codegen:
# filename: specification.yml
# timestamp: 2023-08-30T20:49:24+00:00
from __future__ import annotations
from pydantic import BaseModel
class User(BaseModel):
names: list[str] | None = None
Version:
Additional context
It might also be that this is the expected behavior, but in this case it would be good to improve the documentation, as it's not clear to me what this argument is supposed to do.
Thanks for your good work on this nice project!
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too