]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
♻ Move internal variable for errors in `jsonable_encoder` to put related code closer...
authorGuillermo Quintana Pelayo <36505071+GuilleQP@users.noreply.github.com>
Fri, 26 Aug 2022 13:16:44 +0000 (15:16 +0200)
committerGitHub <noreply@github.com>
Fri, 26 Aug 2022 13:16:44 +0000 (13:16 +0000)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
fastapi/encoders.py

index b1fde73ceb7fcddda1b48b4533f5020f1223306a..6f571edb261d7af5fc1729db8dceda4b57fbf310 100644 (file)
@@ -137,10 +137,10 @@ def jsonable_encoder(
         if isinstance(obj, classes_tuple):
             return encoder(obj)
 
-    errors: List[Exception] = []
     try:
         data = dict(obj)
     except Exception as e:
+        errors: List[Exception] = []
         errors.append(e)
         try:
             data = vars(obj)