-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
timedelta json encoding #247
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
@@ Coverage Diff @@
## master #247 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 11 11
Lines 1463 1478 +15
Branches 270 273 +3
=====================================
+ Hits 1463 1478 +15 |
d6c6bbc to
b620510
Compare
| @@ -134,11 +136,16 @@ def __new__(mcs, name, bases, namespace): | |||
| ) | |||
|
|
|||
| vg.check_for_unused() | |||
| if config.json_encoders: | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can simplify 4 lines into one, because pydantic_encoder will be called inside custom_pydantic_encoder in case if custom encoder not found:
json_encoder = partial(custom_pydantic_encoder, config.json_encoders)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure this won't be slow? I don't really know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be slow, agree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that it's not much extra code and json_encoder could be called a lot, let's keep it like this.
pydantic/json.py
Outdated
| return pydantic_encoder(obj) | ||
|
|
||
|
|
||
| def timedelta_isoformat(td: datetime.timedelta): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing returning type hint
|
Overall looks good to me. |
bd666a1 to
110c7e1
Compare
* build binaries for 3.11 * [full-build] remove 3.11 from windows builds * print commit message for debugging * try ci on push * trigger full build * trigger full build, try again * trigger full build, try again 2 * [skip ci] remove lint prints
an alternative to #220. Needs a few more tests and docs but otherwise complete.
basically, I've added a
json_encodersConfig settings, allowing custom typing encoding defined on a model:@Gr1N and @cfkanesan I'd appreciate your feedback on this.