Skip to content

Add ability to specify dataclass name in dataclass_schema #603

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
May 17, 2023

Conversation

dmontagu
Copy link
Collaborator

This change would be necessary to get the type parameters into the generated loc values when working with generic dataclasses.

I think regardless of what we do with generic dataclasses this is probably a change worth making as:

  • there is no validation-time performance cost, and
  • we can fully control whether there is any change in behavior from the pydantic side

Even though generic dataclasses isn't ready yet on the pydantic side, I'll open this now as I think it will be necessary no matter what we do there.

'ctx': {'dataclass_name': 'FooDataclass[dataclass_args_schema]'},
'input': 123,
'loc': ('foo', 'FooDataclass[cls_name]'),
'msg': 'Input should be a dictionary or an instance of FooDataclass[dataclass_args_schema]',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note the value in ctx and msg comes from the dataclass_args_schema, whereas the value in loc comes from the dataclass_schema.

@codspeed-hq
Copy link

codspeed-hq bot commented May 15, 2023

CodSpeed Performance Report

Merging #603 generic-dataclass-name (6560e78) will not alter performances.

Summary

🔥 0 improvements
❌ 0 regressions
✅ 115 untouched benchmarks

🆕 3 new benchmarks
⁉️ 0 dropped benchmarks

Benchmarks breakdown

Benchmark main generic-dataclass-name Change
🆕 test_set_of_ints_core_duplicates N/A 7.8 ms N/A
🆕 test_set_of_ints_core_json_duplicates N/A 4.6 ms N/A
🆕 test_frozenset_of_ints_duplicates_core N/A 1.1 ms N/A

@dmontagu
Copy link
Collaborator Author

Actually, I guess this may be unnecessary if we take the parametrizations-are-subclasses approach for dataclasses the way we do for BaseModel. I was hoping to avoid that but maybe that's the right way to do it.

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

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

otherwise LGTM

@samuelcolvin samuelcolvin enabled auto-merge (squash) May 17, 2023 14:03
@codecov-commenter
Copy link

Codecov Report

Merging #603 (cbfcc22) into main (3603f10) will increase coverage by 0.02%.
The diff coverage is 100.00%.

❗ Current head cbfcc22 differs from pull request most recent head 6560e78. Consider uploading reports for the commit 6560e78 to get more accurate results

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #603      +/-   ##
==========================================
+ Coverage   94.11%   94.13%   +0.02%     
==========================================
  Files          98       98              
  Lines       13177    13188      +11     
  Branches       25       25              
==========================================
+ Hits        12401    12414      +13     
+ Misses        770      768       -2     
  Partials        6        6              
Impacted Files Coverage Δ
pydantic_core/core_schema.py 96.88% <100.00%> (+<0.01%) ⬆️
src/validators/dataclass.rs 98.24% <100.00%> (+3.97%) ⬆️

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3603f10...6560e78. Read the comment docs.

@samuelcolvin samuelcolvin merged commit 2a7a2f6 into main May 17, 2023
@samuelcolvin samuelcolvin deleted the generic-dataclass-name branch May 17, 2023 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants