datamodel-code-generator icon indicating copy to clipboard operation
datamodel-code-generator copied to clipboard

TypeAlias does not work for python versions <3.10

Open paultop6 opened this issue 1 year ago • 5 comments
trafficstars

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.

paultop6 avatar Feb 09 '24 09:02 paultop6

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.

paultop6 avatar Feb 09 '24 10:02 paultop6

Thank for found bug! I will check your problem in tests soon

denisart avatar Feb 11 '24 08:02 denisart

Thank for found bug! I will check your problem in tests soon

Did you happen to get anywhere with this?

paultop6 avatar Apr 29 '24 15:04 paultop6