Skip to content

Conversation

tpdorsey
Copy link
Contributor

@tpdorsey tpdorsey commented Jul 14, 2023

Change Summary

Related issue number

Closes PYD-107

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 and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @adriangb

@linear
Copy link

linear bot commented Jul 14, 2023

PYD-107 New functionality: Generics improvements

  • Added support for generic dataclasses, typeddicts
  • Automatic model_rebuild for recursive models

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 14, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 65e96f9
Status: ✅  Deploy successful!
Preview URL: https://0c6cee65.pydantic-docs2.pages.dev
Branch Preview URL: https://generics-updates.pydantic-docs2.pages.dev

View logs

@tpdorsey
Copy link
Contributor Author

please review

assert validator.validate_python({'x': None}).x is None
assert validator.validate_python({'x': 1}).x == 1
assert validator.validate_python({'x': 'a'}).x == 'a'
```
Copy link
Member

Choose a reason for hiding this comment

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

Maybe worth noting that if you use the dataclass as a field of a BaseModel or via FastAPI you don't need a TypeAdapter

@@ -158,6 +159,46 @@ print(m.model_dump())

For self-referencing models, see [postponed annotations](postponed_annotations.md#self-referencing-or-recursive-models).

## Rebuild model schema

The model schema can be rebuilt using `model_rebuild()`. This is useful for building recursive generic models.
Copy link
Member

Choose a reason for hiding this comment

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

We need to tell users when it's useful. Something like "we try to determine when this is necessary and error if it wasn't done but you may want to call model_rebuild() proactively when dealing with recursive and/or generics.

@hramezani hramezani enabled auto-merge (squash) July 21, 2023 07:33
@hramezani hramezani merged commit 3e21521 into main Jul 21, 2023
@hramezani hramezani deleted the generics-updates branch July 21, 2023 07:45
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.

3 participants