pre-commit-ci-lite[bot]
2 weeks ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
6 additions and
5 deletions
-
benchmark_encoder.py
-
fastapi/encoders.py
|
|
|
@ -1,7 +1,7 @@ |
|
|
|
import time |
|
|
|
from typing import List, Optional |
|
|
|
from pydantic import BaseModel |
|
|
|
|
|
|
|
from fastapi.encoders import jsonable_encoder |
|
|
|
from pydantic import BaseModel |
|
|
|
|
|
|
|
|
|
|
|
class SubModel(BaseModel): |
|
|
|
@ -13,8 +13,8 @@ class MainModel(BaseModel): |
|
|
|
id: int |
|
|
|
title: str |
|
|
|
sub: SubModel |
|
|
|
items: List[SubModel] |
|
|
|
maybe: Optional[str] = None |
|
|
|
items: list[SubModel] |
|
|
|
maybe: str | None = None |
|
|
|
|
|
|
|
|
|
|
|
def run_benchmark(): |
|
|
|
|
|
|
|
@ -254,7 +254,8 @@ def jsonable_encoder( |
|
|
|
if not sqlalchemy_safe: |
|
|
|
return obj_dict |
|
|
|
return { |
|
|
|
k: v for k, v in obj_dict.items() |
|
|
|
k: v |
|
|
|
for k, v in obj_dict.items() |
|
|
|
if not (isinstance(k, str) and k.startswith("_sa")) |
|
|
|
} |
|
|
|
# Fallback to recursive call for recursive exclude_none/exclude_defaults cleanup |
|
|
|
|