Browse Source

🎨 [pre-commit.ci] Auto format from pre-commit.com hooks

pull/13982/head
pre-commit-ci[bot] 4 weeks ago
parent
commit
dc9a03fc93
  1. 3
      fastapi/encoders.py
  2. 7
      tests/test_jsonable_encoder.py

3
fastapi/encoders.py

@ -14,7 +14,7 @@ from ipaddress import (
from pathlib import Path, PurePath
from re import Pattern
from types import GeneratorType
from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
from typing import Any, Callable, Dict, Optional, Tuple, Type, Union
from uuid import UUID
from fastapi.types import IncEx
@ -102,6 +102,7 @@ encoders_by_class_tuples = generate_encoders_by_class_tuples(ENCODERS_BY_TYPE)
NoneType = type(None)
def jsonable_encoder(
obj: Annotated[
Any,

7
tests/test_jsonable_encoder.py

@ -102,14 +102,13 @@ def test_encode_dict_with_nonprimative_keys():
return hash(self.value)
assert jsonable_encoder(
{CustomString("foo"): "bar"},
custom_encoder={CustomString: lambda v: v.value}
{CustomString("foo"): "bar"}, custom_encoder={CustomString: lambda v: v.value}
) == {"foo": "bar"}
def test_encode_dict_with_custom_encoder_keys():
assert jsonable_encoder(
{"foo": "bar"},
custom_encoder={str: lambda v: "_" + v}
{"foo": "bar"}, custom_encoder={str: lambda v: "_" + v}
) == {"_foo": "_bar"}

Loading…
Cancel
Save