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

Override__subclasscheck__ onModelMetaclass to avoid memory leak and performance issues#11116

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 1 commit intomainfromsubclasscheck
Dec 16, 2024

Conversation

Viicos
Copy link
Member

@ViicosViicos commentedDec 15, 2024
edited
Loading

We avoid relying onABCMeta.__subclasscheck__ unless we're pretty sure. Note that this was wrongly addressed as__instancecheck__ was implemented instead of__subclasscheck__. However, it is not clear if implementing__instancecheck__ fixed existing issues as well, so it is left as is.

Also changed the checked attribute to__pydantic_decorators__, as this is one of the first attributes being set on the class, and it might be that we change the way__pydantic_validator__ is set in the future (e.g. whendefer_build is set, and if we don't implement mock validators anymore).

Fixes#11100.

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

… and performance issuesWe avoid relying on `ABCMeta.__subclasscheck__` unless we're pretty sure.Note that this was wrongly addressed as `__instancecheck__` was implementedinstead of `__subclasscheck__`. However, it is not clear if implementing`__instancecheck__` fixed existing issues as well, so it is left as is.Also changed the checked attribute to `__pydantic_decorators__`, asthis is one of the first attributes being set on the class, and itmight be that we change the way `__pydantic_validator__` is set inthe future (e.g. when `defer_build` is set, and if we don't implementmock validators anymore).
@github-actionsgithub-actionsbot added the relnotes-fixUsed for bugfixes. labelDec 15, 2024
@cloudflare-workers-and-pagesCloudflare Workers and Pages

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit:1922dfe
Status: ✅  Deploy successful!
Preview URL:https://41a7f040.pydantic-docs.pages.dev
Branch Preview URL:https://subclasscheck.pydantic-docs.pages.dev

View logs

@codspeed-hqCodSpeed HQ
Copy link

CodSpeed Performance Report

Merging#11116 willnot alter performance

Comparingsubclasscheck (1922dfe) withmain (d5f4bde)

Summary

✅ 46 untouched benchmarks

@github-actionsGitHub Actions
Copy link
Contributor

Coverage report

Click to see where and how coverage changed

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

This report was generated bypython-coverage-comment-action

Copy link
Contributor

@sydney-runklesydney-runkle left a comment
edited
Loading

Choose a reason for hiding this comment

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

Clean. Nice. Thanks! Could you add a test before we merge?

@Viicos
Copy link
MemberAuthor

What kind of test are you looking for? We already havetest_model_issubclass

sydney-runkle reacted with thumbs up emoji

@sydney-runklesydney-runkle merged commit95c374d intomainDec 16, 2024
55 checks passed
@sydney-runklesydney-runkle deleted the subclasscheck branchDecember 16, 2024 23:15
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
No one assigned
Labels
relnotes-fixUsed for bugfixes.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Memory leak withissubclass(x, BaseModel)
2 participants
@Viicos@sydney-runkle

[8]ページ先頭

©2009-2025 Movatter.jp