Browse Source
🔨 added comments to type checks
Co-authored-by: Maxim Martynov <martinov_m_s_@mail.ru>
pull/13982/head
Ben Brady
4 days ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
5 additions and
2 deletions
-
fastapi/encoders.py
|
|
@ -236,9 +236,12 @@ def encode_value( |
|
|
|
sqlalchemy_safe: bool = True, |
|
|
|
) -> Any: |
|
|
|
if custom_encoder: |
|
|
|
if type(obj) in custom_encoder: |
|
|
|
return custom_encoder[type(obj)](obj) |
|
|
|
# fastpath for exact class match |
|
|
|
obj_type = type(obj) |
|
|
|
if obj_type in custom_encoder: |
|
|
|
return custom_encoder[obj_type](obj) |
|
|
|
|
|
|
|
# fallback to isinstance which uses MRO |
|
|
|
for encoder_type, encoder_instance in custom_encoder.items(): |
|
|
|
if isinstance(obj, encoder_type): |
|
|
|
return encoder_instance(obj) |
|
|
|