datamodel-code-generator
datamodel-code-generator copied to clipboard
TypeAlias does not work for python versions <3.10
Describe the bug
When from typing import TypeAlias is used in the output models, it does not take into consideration that support for this was introduced in python 3.10. Any versions below 3.10 will generate models that will not work.
The potential solution would be to use `from typing_extensions import TypeAlias
To Reproduce
Example schema:
type DummyType {
id: ID!
label: String!
value: Int!
}
Used commandline:
$ datamodel-codegen --input ./example.graphql --input-file-type=graphql --output-model-type pydantic_v2.BaseModel --target-python-version 3.8 --output example_models.py
Expected behavior The outputted example_models.py should be code that can be run using python3.8.
Version:
- OS: [e.g. iOS] Mac OS 14, aws lambda runtime
- Python version: 3.8
- datamodel-code-generator version: [e.g. 22] 0.25.3
Additional context Add any other context about the problem here.
I have a fix for this, but I am struggling to get tests to pass locally. tests/test_main.py::test_enable_version_header always fails, with the following error
importlib.metadata.PackageNotFoundError: No package metadata was found for datamodel-code-generator
Followed development-contribution.md instructions, but still get this error no matter what I try.
Thank for found bug! I will check your problem in tests soon
Thank for found bug! I will check your problem in tests soon
Did you happen to get anywhere with this?