Describe the bug
After digging a bit, I found a strange behavior, which could be related to #270:
I generate my code like this.
As the target version is not PY_36, in any case the line
from __future__ import annotations
will be added. If I remove the line, everything will then work fine. Otherwise, it will go rogue.
To Reproduce
Used commandline:
$ datamodel-codegen --input schema/build-info.schema.json --custom-file-header-path .licenseheader --output src/buildinfo_om/_model.py --output-model-type dataclasses.dataclass --enum-field-as-literal all --field-constraints --set-default-enum-member --strict-types str bytes int float bool --use-annotated --use-generic-container-types --use-non-positive-negative-number-constrained-types --use-double-quotes --use-standard-collections --use-subclass-enum --use-union-operator --capitalise-enum-members --use-default-kwarg --use-field-description --disable-appending-item-suffix --enable-version-header --target-python-version 3.11 --use-schema-description --use-title-as-name --no-color --input-file-type jsonschema
Expected behavior
I can reflect on the datatypes with python. This actually does not work.
from dataclasses import fields
from typing import get_options, get_args
from ._model import Agent
name = fields(Agent)[0]
print (get_origin(name.type))
print (get_args(name.type))
Expected:
<class 'types.UnionType'>
(<class 'str'>, <class 'NoneType'>)
Actual:
None
()
If I drop the line from the resulting code, inspection works again properly...
Version:
Additional context
Add any other context about the problem here.
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