Browse Source

Simplify and improve jsonable_encoder (#1754)

Co-authored-by: nimashadix <[email protected]>
pull/1830/head
Nima Mashhadi M. Reza 5 years ago
committed by GitHub
parent
commit
3063ad83ec
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      fastapi/encoders.py

7
fastapi/encoders.py

@ -16,12 +16,9 @@ DictIntStrAny = Dict[Union[int, str], Any]
def generate_encoders_by_class_tuples(
type_encoder_map: Dict[Any, Callable]
) -> Dict[Callable, Tuple]:
encoders_by_classes: Dict[Callable, List] = defaultdict(list)
encoders_by_class_tuples: Dict[Callable, Tuple] = defaultdict(tuple)
for type_, encoder in type_encoder_map.items():
encoders_by_classes[encoder].append(type_)
encoders_by_class_tuples: Dict[Callable, Tuple] = {}
for encoder, classes in encoders_by_classes.items():
encoders_by_class_tuples[encoder] = tuple(classes)
encoders_by_class_tuples[encoder] += (type_,)
return encoders_by_class_tuples

Loading…
Cancel
Save