Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Dataclasses docs #6470

Merged
merged 12 commits into from Jul 11, 2023
Merged

Update Dataclasses docs #6470

merged 12 commits into from Jul 11, 2023

Conversation

tpdorsey
Copy link
Contributor

@tpdorsey tpdorsey commented Jul 5, 2023

  • document new dataclasses features
  • review docstrings
  • update typeadapter links

Change Summary

Related issue number

Closes PYD-54

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @davidhewitt

@linear
Copy link

linear bot commented Jul 5, 2023

@cloudflare-pages
Copy link

cloudflare-pages bot commented Jul 5, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: c1766c0
Status: ✅  Deploy successful!
Preview URL: https://600858b6.pydantic-docs2.pages.dev
Branch Preview URL: https://dataclass-docs.pydantic-docs2.pages.dev

View logs

@tpdorsey
Copy link
Contributor Author

tpdorsey commented Jul 6, 2023

please review

Copy link
Contributor

@ybressler ybressler left a comment

Choose a reason for hiding this comment

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

Thank you for going through the documentation! Your changes are scrupulous.

I left some comments + requested changes related to style + grammar. Overall, looks really good.

docs/migration.md Outdated Show resolved Hide resolved
docs/migration.md Outdated Show resolved Hide resolved
docs/migration.md Outdated Show resolved Hide resolved
docs/migration.md Outdated Show resolved Hide resolved
docs/usage/dataclasses.md Outdated Show resolved Hide resolved
docs/usage/dataclasses.md Show resolved Hide resolved
docs/usage/dataclasses.md Show resolved Hide resolved
pydantic/dataclasses.py Outdated Show resolved Hide resolved
docs/migration.md Outdated Show resolved Hide resolved
docs/migration.md Outdated Show resolved Hide resolved
docs/usage/dataclasses.md Outdated Show resolved Hide resolved
docs/usage/dataclasses.md Show resolved Hide resolved
pydantic/dataclasses.py Outdated Show resolved Hide resolved
Co-authored-by: Yaakov Bressler <40807730+ybressler@users.noreply.github.com>
docs/migration.md Outdated Show resolved Hide resolved
@tpdorsey
Copy link
Contributor Author

tpdorsey commented Jul 7, 2023

please review

Copy link
Contributor

@ybressler ybressler left a comment

Choose a reason for hiding this comment

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

Looks good! I have one small change about one word ;)

Also, one outstanding thread about how to resolve potential confusion with model_config for basemodels and config for dataclasses. Pending resolution, we should be good to go!

pydantic/dataclasses.py Outdated Show resolved Hide resolved
pydantic/dataclasses.py Outdated Show resolved Hide resolved
Copy link
Contributor

@ybressler ybressler left a comment

Choose a reason for hiding this comment

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

Changes look great!

@tpdorsey
Copy link
Contributor Author

Please review

@tpdorsey tpdorsey merged commit ec256b3 into main Jul 11, 2023
49 checks passed
@tpdorsey tpdorsey deleted the dataclass-docs branch July 11, 2023 14:53
Comment on lines +138 to +139
Pydantic dataclasses do not support [`extra='allow'`](model_config/#extra-attributes), where extra fields passed
to the initializer would be stored as extra attributes on the dataclass.
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @tpdorsey! Could you help me understand what you meant by this diff? It looks to me like the current support for extra="allow" is the same as it was after #2557 (the PR where the removed copy was introduced), but I'm wondering if I'm missing something.

With extra="allow", extra values passed to __init__ still end up in the instantiated object, but just aren't surfaced via __str__. Example script:

from pydantic.dataclasses import dataclass

@dataclass(config=dict(extra="allow"))
class Example:
    ...

obj = Example(a=1, b=2)
print(obj)
print(f"Extra: a={obj.a}, b={obj.b}")

This script yields the following output when running with the latest pydantic==2.3.0:

Example()
Extra: a=1, b=2

Copy link
Member

Choose a reason for hiding this comment

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

Hey, Could you please make an issue or ask this in a GitHub discussion?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the quick response, @hramezani — opened #7362 to discuss.

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.

None yet

5 participants