Skip to content

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

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

Merged
merged 3 commits into from
Nov 13, 2024

Conversation

Viicos
Copy link
Member

@Viicos Viicos commented Nov 11, 2024

Also follow stdlib dataclasses for signature parameter defaults. If a default factory is used, the placeholder '<factory>' 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 `'<factory>'` is
used.
@github-actions github-actions bot added the relnotes-fix Used for bugfixes. label Nov 11, 2024
Copy link

cloudflare-workers-and-pages bot commented Nov 11, 2024

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

Copy link

codspeed-hq bot commented Nov 11, 2024

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%

Copy link
Contributor

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

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

@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
Copy link
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

Copy link
Contributor

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

Very impressed with this implementation, good find.

Feel free to merge at your leisure.

@Viicos Viicos merged commit 2899ca8 into main Nov 13, 2024
54 checks passed
@Viicos Viicos deleted the model-signature branch November 13, 2024 10:26
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