Gowee / json2pyi

Generate Python type definitions from a JSON sample (both Pydantic BaseModel and TypedDict are supported)
https://json2pyi.pages.dev
46 stars 1 forks source link

support class based TypedDict syntax #1

Closed graingert closed 2 years ago

graingert commented 2 years ago

first of all thanks a lot for this tool! It did almost exactly what I needed

https://www.python.org/dev/peps/pep-0589/#class-based-syntax

currently json2pyi generates:

Move = TypedDict("Movie", {"name": str, "year": int})

but I'd like it to generate:

class Movie(TypedDict):
    name: str
    year: int

where possible

Gowee commented 2 years ago

Thanks for your suggestion! It turns out I overlooked that section.

The class-based format looks trivial to adapt to. I will look into PEP589 carefully later.

Gowee commented 2 years ago

I've made a quick fix by https://github.com/Gowee/json2pyi/commit/1955a93db98e1059a39d86143a7cf65106409715. It will take a while to be deployed :rocket: onto the web app: https://json2pyi.pages.dev/#TypedDictClass.

Gowee commented 2 years ago

I just remember that the missing class-based TypedDict was due to regression after a refactor.

Should be fixed. Closing it for now. Please let me know if there are any other problems. Thanks!