Skip to content

Make __signature__ a lazy property, do not deepcopy defaults - #10818

Merged
Viicos merged 3 commits into
mainfrom
model-signature
Nov 13, 2024
Merged

Viicos merged 3 commits into
mainfrom
model-signature

Conversation

@Viicos

@Viicos Viicos commented Nov 11, 2024 •

Copy link
Copy Markdown
Member

Also follow stdlib dataclasses for signature parameter defaults. If a default factory is used, the placeholder '' is used.

Related issue number

Fixes #10771, #10656

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

Also follow stdlib dataclasses for signature parameter defaults.
If a default factory is used, the placeholder `''` is
used.
@github-actions github-actions Bot added the relnotes-fix Used for bugfixes. label Nov 11, 2024
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 11, 2024 •

Copy link
Copy Markdown

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: fda5e91
Status: ✅  Deploy successful!
Preview URL: https://232345cd.pydantic-docs.pages.dev
Branch Preview URL: https://model-signature.pydantic-docs.pages.dev

View logs

@codspeed

codspeed Bot commented Nov 11, 2024 •

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #10818 will improve performances by 11.23%

Comparing model-signature (fda5e91) with main (8bad227)

Summary

⚡ 9 improvements
✅ 35 untouched benchmarks

Benchmarks breakdown

Benchmark main model-signature Change
⚡ test_model_validators_serializers 1.1 ms 1.1 ms +5.76%
⚡ test_nested_model_schema_generation 1.4 ms 1.4 ms +7.13%
⚡ test_recursive_model_schema_generation 1.4 ms 1.3 ms +7.45%
⚡ test_simple_model_schema_generation 1,042.9 µs 938.1 µs +11.17%
⚡ test_tagged_union_with_callable_discriminator_schema_generation 2.1 ms 2 ms +5.22%
⚡ test_tagged_union_with_str_discriminator_schema_generation 2 ms 1.9 ms +5.47%
⚡ test_deeply_nested_recursive_model_schema_generation 1.7 ms 1.6 ms +5.72%
⚡ test_generic_recursive_model_schema_generation 1.2 ms 1.1 ms +9.03%
⚡ test_simple_recursive_model_schema_generation 1,003 µs 901.8 µs +11.23%

@sydney-runkle sydney-runkle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is promising - are there more class attributes for which we could do this? Gives us a nice boost on schema builds :)

Comment thread pydantic/_internal/_utils.py Outdated
Comment thread pydantic/_internal/_utils.py Outdated
@sydney-runkle sydney-runkle added awaiting author response awaiting response from issue opener awaiting author revision awaiting changes from the PR author and removed awaiting author response awaiting response from issue opener labels Nov 11, 2024
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

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

This report was generated by python-coverage-comment-action

@sydney-runkle sydney-runkle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Very impressed with this implementation, good find.

Feel free to merge at your leisure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting author revision awaiting changes from the PR author relnotes-fix Used for bugfixes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default value can fail to be deepcopied during model signature generation

2 participants