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

Allow config and bases to be specified together increate_model()#11714

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
Viicos merged 1 commit intomainfromcreate-model-config-base
Apr 9, 2025

Conversation

Viicos
Copy link
Member

Change Summary

Fixes#2137.

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

@github-actionsgithub-actionsbot added the relnotes-fixUsed for bugfixes. labelApr 8, 2025
@hyperlint-aiHyperlint AI
Copy link
Contributor

PR Change Summary

Allowed configuration and base classes to be specified together in thecreate_model() function, addressing a previously raised issue.

  • Enabled the use of both__config__ and__base__ increate_model()
  • Removed outdated error handling example related tocreate_model configuration
  • Updated documentation to reflect the new functionality

Modified Files

  • docs/errors/usage_errors.md

How can I customize these reviews?

Check out theHyperlint AI Reviewer docs for more information on how to customize the review.

If you just want to ignore it on this PR, you can add thehyperlint-ignore label to the PR. Future changes won't trigger a Hyperlint review.

Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to addhyperlint-ignore to the PR to ignore the link check for this PR.

@cloudflare-workers-and-pagesCloudflare Workers and Pages
Copy link

cloudflare-workers-and-pagesbot commentedApr 8, 2025
edited
Loading

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit:7a702a7
Status: ✅  Deploy successful!
Preview URL:https://5cf8e1f1.pydantic-docs.pages.dev
Branch Preview URL:https://create-model-config-base.pydantic-docs.pages.dev

View logs

@codspeed-hqCodSpeed HQ
Copy link

codspeed-hqbot commentedApr 8, 2025
edited
Loading

CodSpeed Performance Report

Merging#11714 willnot alter performance

Comparingcreate-model-config-base (7a702a7) withmain (04fd639)

Summary

✅ 46 untouched benchmarks

@ViicosViicosforce-pushed thecreate-model-config-base branch from46d0e9e to7a702a7CompareApril 8, 2025 10:32
@ViicosViicos added relnotes-changeUsed for changes to existing functionality which don't have a better categorization. and removed relnotes-fixUsed for bugfixes. labelsApr 8, 2025
@github-actionsGitHub Actions
Copy link
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic
  main.py
Project Total 

This report was generated bypython-coverage-comment-action

Copy link
Contributor

@davidhewittdavidhewitt left a comment

Choose a reason for hiding this comment

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

I assume that the original limitation was added because inheritance from a base class will set config. How does that config merge with the explicitly set config? Is that where confusion may occur? (e.g. can this do weird things like make the parent model fields all strict?)

@Viicos
Copy link
MemberAuthor

How does that config merge with the explicitly set config?

It will be equivalent to the following, as shown in the added test:

classBase(BaseModel):a:strmodel_config= {'str_to_lower':True}classModel(Base):model_config= {'str_max_length':3}

Which will result inModel having both configuration values.create_model() is in fact completely equivalent to normal subclassing, just that it is meant to be dynamic.

(e.g. can this do weird things like make the parent model fields all strict?)

as in "normal" subclassing, this shouldn't be the case.

Copy link
Contributor

@davidhewittdavidhewitt left a comment

Choose a reason for hiding this comment

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

Ah ok, that justification makes sense to me. LGTM with just one question.

@ViicosViicos merged commit8f6508a intomainApr 9, 2025
64 checks passed
@ViicosViicos deleted the create-model-config-base branchApril 9, 2025 09:35
@ViicosViicos added the backport-2.11Needs backport to 2.11 labelApr 29, 2025
Viicos added a commit that referenced this pull requestApr 29, 2025
The limitation was added back in the early days of Pydantic, when `create_model()` was implemented. It is no longer necessary.Backport of:#11714
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@davidhewittdavidhewittdavidhewitt approved these changes

Assignees
No one assigned
Labels
backport-2.11Needs backport to 2.11relnotes-changeUsed for changes to existing functionality which don't have a better categorization.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Provide a Base and a Config in create_model
2 participants
@Viicos@davidhewitt

[8]ページ先頭

©2009-2025 Movatter.jp