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

PrivateAttr is passed from Annotated default position #8004

Merged
merged 9 commits into from
Nov 3, 2023

Conversation

tabassco
Copy link
Contributor

@tabassco tabassco commented Nov 3, 2023

Change Summary

See related issue for a minimal example.

  • When creating private fields from typing.Annotated, the default method gets thrown out in the current implementation.
  • This Pull-Requests adds functionality to check wether the Default in the Anntotated[] definition already is a PrivateAttr and uses it straight away.

Related issue number

fix #7955

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

Tim Kreitner added 2 commits November 3, 2023 12:03
Co-authored-by: Samuel Colvin <s@muelcolvin.com>

<!-- Thank you for your contribution! -->
<!-- Unless your change is trivial, please create an issue to discuss the change before creating a PR -->

## Change Summary
See related issue for a minimal example.

- When creating private fields from typing.Annotated, the default method gets thrown out in the current implementation.
- This Pull-Requests adds functionality to check wether the Default in the `Anntotated[]` definition already is a `PrivateAttr` and uses it straight away.

## Related issue number

fix pydantic#7955

## 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**
pdm.lock Outdated Show resolved Hide resolved
pydantic/_internal/_model_construction.py Outdated Show resolved Hide resolved
@sydney-runkle sydney-runkle added the relnotes-fix Used for bugfixes. label Nov 3, 2023
Copy link
Member

@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.

Looks great, thanks for the contribution!

@sydney-runkle sydney-runkle merged commit b7d9281 into pydantic:main Nov 3, 2023
59 checks passed
@tabassco tabassco deleted the 7955-fix-attr-error branch November 3, 2023 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes-fix Used for bugfixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use PrivateAttr with Annotated will cause AttributeError when getting private attr.
3 participants