-
Notifications
You must be signed in to change notification settings - Fork 292
fix serialization of subclasses #860
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
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #860 +/- ##
==========================================
- Coverage 93.91% 93.78% -0.13%
==========================================
Files 104 104
Lines 15414 15485 +71
Branches 25 25
==========================================
+ Hits 14476 14523 +47
- Misses 932 956 +24
Partials 6 6
Continue to review full report in Codecov by Sentry.
|
CodSpeed Performance ReportMerging #860 will degrade performances by 29.42%Comparing Summary
Benchmarks breakdown
|
please review. |
Does this apply only if the type is |
This should work on both Personally I think we should serialize subclasses without an error, but the |
If i think about this from a API / fastapi perspecitve, then the schema will want to define the expected output format (float). If the original structure is creating a float64, or an actual float (explicitly casting to float) shouldn't really matter? It should fail if the types are incompatible - but i don't really see that it should fail if a np.float64 is used instead of a float - as the 2 are actually compatible types. |
sp @xmatthias are you saying this PR is right or wrong? |
@samuelcolvin sorry for being imprecise
I think it's correct to serialize int64 as int - as it's a subclass of int - and my intend for the output is to have it as an integer. |
6e29966
to
946710c
Compare
The integration test failure is trivial; the test in Pydantic is using |
Change Summary
added a fallback method to look for subclasses of types we know how to serialize.
This should work for both custom
__isinstancecheck__
logic, and cases where types are used as mixins, e.g.numpy.float64
.Related issue number
fix pydantic/pydantic#6963
Selected Reviewer: @davidhewitt