Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Supportdefer_build for Pydantic dataclasses#10313

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sydney-runkle merged 7 commits intomainfromdc-defer-build
Sep 18, 2024
Merged

Conversation

Viicos
Copy link
Member

Also return early ifdefer_build is set for Pydantic models.

Change Summary

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

sydney-runkle reacted with thumbs up emoji
Also return early if `defer_build` is set for Pydantic models.
@github-actionsgithub-actionsbot added the relnotes-fixUsed for bugfixes. labelSep 5, 2024
@cloudflare-workers-and-pagesCloudflare Workers and Pages
Copy link

cloudflare-workers-and-pagesbot commentedSep 5, 2024
edited
Loading

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit:7ae6da8
Status: ✅  Deploy successful!
Preview URL:https://c4413a6e.pydantic-docs.pages.dev
Branch Preview URL:https://dc-defer-build.pydantic-docs.pages.dev

View logs

@codspeed-hqCodSpeed HQ
Copy link

codspeed-hqbot commentedSep 5, 2024
edited
Loading

CodSpeed Performance Report

Merging#10313 willnot alter performance

Comparingdc-defer-build (7ae6da8) withmain (59a3de7)

Summary

✅ 49 untouched benchmarks

@github-actionsGitHub Actions
Copy link
Contributor

github-actionsbot commentedSep 5, 2024
edited
Loading

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic
  dataclasses.py
  pydantic/_internal
  _dataclasses.py
  _model_construction.py
Project Total 

This report was generated bypython-coverage-comment-action

Copy link
Contributor

@sydney-runklesydney-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, left one comment re the_force_build argument - would like to avoid that if possible.

I've submitted#10329, which we can probably merge + rebase with to make this PR just a bit more simple.

@Viicos
Copy link
MemberAuthor

Viicos commentedSep 18, 2024
edited
Loading

So the reason why the added_force_build argument was required is because currently ultimately,rebuild_dataclass callscomplete_dataclass. Because the configuration can come from both the decorator or the__pydantic_config__ attribute,complete_dataclass setscls.__pydantic_config__:

cls.__pydantic_config__=config_wrapper.config_dict# type: ignore

So that the following works as expected:

@pydantic_dataclass(config={'strict':True})classDC:a:intassertDC.__pydantic_config__== {'strict':True}

If inrebuild_dataclass, we pass a new config object, as done currently here:

existing_config=getattr(cls,'__pydantic_config__', {})
new_config= {**existing_config,'defer_build':False}
return_pydantic_dataclasses.complete_dataclass(
cls,
_config.ConfigWrapper(new_config,check=False),
raise_errors=raise_errors,
types_namespace=types_namespace,
)

The following will happen:

@pydantic_dataclassclassDC:__pydantic_config__= {'defer_build':True}# or as a decorator parameter, doesn't matterassertDC.__pydantic_config__== {'defer_build':True}rebuild_dataclass(DC)assertDC.__pydantic_config__== {'defer_build':True}# AssertionError, `'defer_build'` is now set to `False`

And is inconsistent with theBaseModel behavior. Besides, I think the config dict on models and dataclasses shouldn't change after the class is defined, no matter if a rebuild was performed or not (and this is what's causing issues withTypeAdapter failing tests I think).

@sydney-runkle
Copy link
Contributor

And is inconsistent with the BaseModel behavior. Besides, I think the config dict on models and dataclasses shouldn't change after the class is defined, no matter if a rebuild was performed or not (and this is what's causing issues with TypeAdapter failing tests I think).

I see, makes sense. Let's revert back then to use the_force_build flag. Apologies for the back and forth on the diff.

Copy link
Contributor

@sydney-runklesydney-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!

@sydney-runklesydney-runkle added relnotes-feature and removed awaiting author revisionawaiting changes from the PR author relnotes-fixUsed for bugfixes. labelsSep 18, 2024
@sydney-runklesydney-runkle changed the titleRespectdefer_build for Pydantic dataclassesSupportdefer_build for Pydantic dataclassesSep 18, 2024
@sydney-runklesydney-runkle merged commit7ac0eb9 intomainSep 18, 2024
61 checks passed
@sydney-runklesydney-runkle deleted the dc-defer-build branchSeptember 18, 2024 13:56
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@sydney-runklesydney-runklesydney-runkle approved these changes

Assignees

@ViicosViicos

Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Viicos@sydney-runkle

[8]ページ先頭

©2009-2025 Movatter.jp