Skip to content

Conversation

Viicos
Copy link
Member

@Viicos Viicos commented Oct 22, 2024

Change Summary

Closes #10679 along the way

Related issue number

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

hyperlint-ai[bot]

This comment was marked as outdated.

Copy link

cloudflare-workers-and-pages bot commented Oct 22, 2024

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: d17a77a
Status: ✅  Deploy successful!
Preview URL: https://410917ea.pydantic-docs.pages.dev
Branch Preview URL: https://dataclass-docs.pydantic-docs.pages.dev

View logs

behavior of stdlib dataclasses may prevail. For example, any extra fields present on a Pydantic dataclass with
[`extra`][pydantic.config.ConfigDict.extra] set to `'allow'` are omitted in the dataclass' string representation.

## Nested dataclasses
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we simplify this section and the following one with a single Similarly to Pydantic models, nested dataclasses and generics are supported (and we refer to the relevant model documentation)? Imo the added value is quite low here, we would expect the examples to work anyway

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this as long as we link to model docs. Maybe we could add a few other notes as well like json schema, etc.

validation will be applied (and the [configuration](#dataclass-config) stays the same). This means that using a stdlib or a Pydantic
dataclass as a field annotation is functionally equivalent.

```py
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example simplified a bit

Copy link

codspeed-hq bot commented Oct 22, 2024

CodSpeed Performance Report

Merging #10686 will not alter performance

Comparing dataclass-docs (d17a77a) with main (dc1ee23)

Summary

✅ 44 untouched benchmarks


When you initialize a dataclass, it is possible to execute code *before* or *after* validation
with the help of the [`@model_validator`](validators.md#model-validators) decorator `mode` parameter.
Validators also work with Pydantic dataclasses:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example below moved from the validators.md file

Copy link
Contributor

github-actions bot commented Oct 22, 2024

Coverage report

This PR does not seem to contain any modification to coverable code.

Copy link
Contributor

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Left a few quick notes :)

behavior of stdlib dataclasses may prevail. For example, any extra fields present on a Pydantic dataclass with
[`extra`][pydantic.config.ConfigDict.extra] set to `'allow'` are omitted in the dataclass' string representation.

## Nested dataclasses
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this as long as we link to model docs. Maybe we could add a few other notes as well like json schema, etc.

hyperlint-ai[bot]

This comment was marked as outdated.

hyperlint-ai[bot]

This comment was marked as outdated.

Copy link
Contributor

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great otherwise, happy to merge after the below tweak

@Viicos Viicos enabled auto-merge (squash) October 23, 2024 19:37
hyperlint-ai[bot]

This comment was marked as outdated.

@Viicos Viicos merged commit af32a86 into main Oct 23, 2024
60 checks passed
@Viicos Viicos deleted the dataclass-docs branch October 23, 2024 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better document Pydantic dataclasses configuration

2 participants