Skip to content

support __pydantic_extra__ when serializing #576

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 11 commits into from
May 4, 2023

Conversation

samuelcolvin
Copy link
Member

No description provided.

@codspeed-hq
Copy link

codspeed-hq bot commented May 3, 2023

CodSpeed Performance Report

Merging #576 serialize-__pydantic_extra__ (0fa626f) will not alter performances.

Summary

🔥 0 improvements
❌ 0 regressions
✅ 112 untouched benchmarks

🆕 2 new benchmarks
⁉️ 0 dropped benchmarks

Benchmarks breakdown

Benchmark main serialize-__pydantic_extra__ Change
🆕 test_core_model_py_extra N/A 58.3 µs N/A
🆕 test_core_model_json_extra N/A 55.7 µs N/A

@codecov-commenter
Copy link

codecov-commenter commented May 3, 2023

Codecov Report

Merging #576 (0d1712d) into main (d3f97e7) will increase coverage by 0.00%.
The diff coverage is 94.61%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #576   +/-   ##
=======================================
  Coverage   94.18%   94.18%           
=======================================
  Files          95       96    +1     
  Lines       12974    13019   +45     
  Branches       24       24           
=======================================
+ Hits        12219    12262   +43     
- Misses        749      751    +2     
  Partials        6        6           
Impacted Files Coverage Δ
src/serializers/mod.rs 99.02% <ø> (ø)
src/serializers/shared.rs 89.65% <ø> (ø)
src/serializers/type_serializers/function.rs 95.71% <ø> (+0.02%) ⬆️
src/serializers/type_serializers/other.rs 84.90% <ø> (ø)
src/serializers/type_serializers/union.rs 81.14% <ø> (ø)
src/serializers/type_serializers/dataclass.rs 97.05% <85.71%> (-2.95%) ⬇️
src/serializers/fields.rs 94.44% <94.44%> (ø)
src/serializers/type_serializers/model.rs 93.91% <96.15%> (+0.98%) ⬆️
pydantic_core/core_schema.py 96.95% <100.00%> (+<0.01%) ⬆️
src/serializers/type_serializers/typed_dict.rs 96.87% <100.00%> (+2.13%) ⬆️
... and 1 more

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 d3f97e7...0d1712d. Read the comment docs.

@samuelcolvin samuelcolvin force-pushed the serialize-__pydantic_extra__ branch from e416bf8 to 551fa1f Compare May 4, 2023 07:46
@samuelcolvin samuelcolvin force-pushed the serialize-__pydantic_extra__ branch from 551fa1f to 193b998 Compare May 4, 2023 10:36
Copy link
Member

@adriangb adriangb left a comment

Choose a reason for hiding this comment

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

This looks good to me generally. Can you add some background in the PR description to explain what the new behavior for dataclass and models is, (what was it before, how does this PR change it)

Comment on lines +78 to +86
#[derive(Debug, Clone)]
pub(super) enum FieldsMode {
// typeddict with no extra items
SimpleDict,
// a model - get `__dict__` and `__pydantic_extra__` - `GeneralFieldsSerializer` will get a tuple
ModelExtra,
// typeddict with extra items - one dict with extra items
TypedDictAllow,
}
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

Comment on lines +135 to +142
macro_rules! option_length {
($op_has_len:expr) => {
match $op_has_len {
Some(ref has_len) => has_len.len(),
None => 0,
}
};
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm guessing this has to be a macro to support multiple input types that have a .len() without generics / enums?

Copy link
Collaborator

@dmontagu dmontagu left a comment

Choose a reason for hiding this comment

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

I didn't carefully compare TypedDictSerializer to GeneralFieldsSerializer or anything, but generally this looks good to me.

@samuelcolvin samuelcolvin merged commit 82fb0e9 into main May 4, 2023
@samuelcolvin samuelcolvin deleted the serialize-__pydantic_extra__ branch May 4, 2023 20:13
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.

4 participants