Skip to content

Change dataclasses.dataclass to pydantic.dataclasses.dataclass#105

Open
deanpoulos wants to merge 2 commits into
mainfrom
feature/pydantic_dataclasses
Open

Change dataclasses.dataclass to pydantic.dataclasses.dataclass#105
deanpoulos wants to merge 2 commits into
mainfrom
feature/pydantic_dataclasses

Conversation

@deanpoulos

@deanpoulos deanpoulos commented Feb 5, 2025

Copy link
Copy Markdown
Collaborator

This change is motivated by the following use-case.

Let's say I create a QuAM object to represent my QPU. Since every QuAM component is also a @quam_dataclass, I can use Pydantic's dataclass scheme generation feature as follows:

Do this to generate a schema:

schema = TypeAdapter(QuAM).json_schema()
with open("schema.json", "w+") as f:
   json.dump(schema, f, indent=2))

Then, if you load the schema into my IDE using a JSON schema mapping, you get required-field checking, type-checking, attribute hints, etc.
trimmed_output.webm

I believe we can enhance the number of schema features we exploit by doing something like this:

@quam_dataclass
class XYZ:
        age: Optional[int] = pydantic.dataclasses.field(metadata=dict(
            description="some description"
        )
    )

but I haven't tested it.

Could you please run this against tests and consider whether it will break fundamental features of QuAM? If not, I believe it would be a great improvement.

@nulinspiratie

Copy link
Copy Markdown
Contributor

If it doesn't break anything, this is probably a pretty major improvement for QUAM, great idea!
I'm a bit surprised that it works, and it also seems to be okay with references??
Very strange, I will investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants