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 pathlib import Path, PurePath
from re import Pattern from re import Pattern
from types import GeneratorType 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 uuid import UUID
from fastapi.types import IncEx from fastapi.types import IncEx
@ -102,6 +102,7 @@ encoders_by_class_tuples = generate_encoders_by_class_tuples(ENCODERS_BY_TYPE)
NoneType = type(None) NoneType = type(None)
def jsonable_encoder( def jsonable_encoder(
obj: Annotated[ obj: Annotated[
Any, Any,

7
tests/test_jsonable_encoder.py

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

Loading…
Cancel
Save