koxudaxi / datamodel-code-generator

Pydantic model and dataclasses.dataclass generator for easy conversion of JSON, OpenAPI, JSON Schema, and YAML data sources.
https://koxudaxi.github.io/datamodel-code-generator/
MIT License
2.44k stars 281 forks source link

feat: new cli option --use-exact-imports #1983

Closed alpoi-x closed 2 weeks ago

alpoi-x commented 1 month ago

Adds a new CLI options --use-exact-imports (off by default) to import types directly instead of modules. For example:

from . import bean_type

class Bean(BaseModel):
    bean_type: bean_type.BeanType

becomes

from .bean_type import BeanType

class Bean(BaseModel):
    bean_type: BeanType

Resolves #1982 and potentially #1683

lord-haffi commented 4 weeks ago

This would indeed fix #1683. Also supersedes #1684.

codecov[bot] commented 4 weeks ago

Codecov Report

Attention: Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@f023016). Learn more about missing BASE report.

Files Patch % Lines
datamodel_code_generator/parser/base.py 77.77% 1 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1983 +/- ## ======================================= Coverage ? 98.81% ======================================= Files ? 37 Lines ? 4212 Branches ? 981 ======================================= Hits ? 4162 Misses ? 31 Partials ? 19 ``` | [Flag](https://app.codecov.io/gh/koxudaxi/datamodel-code-generator/pull/1983/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Koudai+Aono) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/koxudaxi/datamodel-code-generator/pull/1983/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Koudai+Aono) | `98.48% <84.61%> (?)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Koudai+Aono#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codspeed-hq[bot] commented 4 weeks ago

CodSpeed Performance Report

Merging #1983 will not alter performance

Comparing alpoi-x:use-exact-imports (b6810b5) with main (f023016)

Summary

✅ 29 untouched benchmarks