sbrunner / jsonschema-gentypes

Tool to generate Python types based on TypedDict from a JSON Schema
BSD 2-Clause "Simplified" License
39 stars 13 forks source link

Generated code import ordering is random #856

Open dbushong opened 8 months ago

dbushong commented 8 months ago

The list of imports are collected in a set() (I believe) and so their ordering is not stable. We should either sort them when emitting code or use a stable method of making them unique (e.g. a dict()). Having the code change every time it is regenerated makes for undesirable diff churn when generated code is checked into a repo and regularly regenerated as part of automated tooling.

sbrunner commented 8 months ago

Personally, I'm not concerned because I do an isort on the generate code via a pre-commit :-)

jacksonj04 commented 3 weeks ago

This is causing us a bit of trouble when running the tool via pre-commit, because pre-commit will say the check has "failed" on the basis of it having changed a file, even if the only change is that the order of the imports has swapped around.

I've opened a quick PR to address this with a sorted().