Skip to content

Support native dataclasses out of the boxΒ #760

@uriva

Description

@uriva

I use the native dataclasses api, and I imagine that this will be the standard for python apps in the coming future, so I think fastapi should support them without requiring the use of pydantic.

Otherwise, a heavily nested dc will require changing a lot of code.

The common situation is this:

@dataclasses.dataclass(frozen=True)
class A:
  b: B

@dataclasses.dataclass(frozen=True)
class B:
   ...

Where I want to use A in my fastapi app, but I end up having to convert A to pydantic (via mix-in or by giving up dataclasses features).

Even if I do that, I might need to convert B as well, so this is quite a big change to introduce for an api that's supposed to affect just the networking side of things.

Side note: I'm using dataclasses_json to convert to json, so I have two decorators.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions