Skip to content

Update Dataclasses docs#6470

Merged
tpdorsey merged 12 commits intomainfrom
dataclass-docs
Jul 11, 2023
Merged

Update Dataclasses docs#6470
tpdorsey merged 12 commits intomainfrom
dataclass-docs

Conversation

@tpdorsey
Copy link
Copy Markdown
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
Copy Markdown

linear Bot commented Jul 5, 2023

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-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
Copy Markdown
Contributor Author

tpdorsey commented Jul 6, 2023

please review

Copy link
Copy Markdown
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.

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

tpdorsey commented Jul 7, 2023

please review

Copy link
Copy Markdown
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!

Comment thread pydantic/dataclasses.py Outdated
Comment thread pydantic/dataclasses.py Outdated
Copy link
Copy Markdown
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 and others added 4 commits July 10, 2023 13:55
@tpdorsey
Copy link
Copy Markdown
Contributor Author

Please review

@tpdorsey tpdorsey merged commit ec256b3 into main Jul 11, 2023
@tpdorsey tpdorsey deleted the dataclass-docs branch July 11, 2023 14:53
Comment thread docs/usage/dataclasses.md
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

5 participants