diff --git a/fast_depends/core/builder.py b/fast_depends/core/builder.py index 85caa060..a7bf5785 100644 --- a/fast_depends/core/builder.py +++ b/fast_depends/core/builder.py @@ -1,4 +1,5 @@ import inspect +from copy import deepcopy from typing import ( TYPE_CHECKING, Any, @@ -102,7 +103,7 @@ def build_call_model( if isinstance(next_custom, Dependant): dep = next_custom elif isinstance(next_custom, CustomField): - custom = next_custom + custom = deepcopy(next_custom) else: # pragma: no cover raise AssertionError("unreachable") diff --git a/tests/library/test_custom.py b/tests/library/test_custom.py index 7acaf2ee..d44f2ec4 100644 --- a/tests/library/test_custom.py +++ b/tests/library/test_custom.py @@ -63,6 +63,21 @@ def __init__(self, key: int = Header()): assert T(headers={"key": 1}).key == 1 +def test_reusable_annotated() -> None: + HeaderKey = Annotated[float, Header(cast=False)] + + @inject + def sync_catch(key: HeaderKey) -> float: + return key + + @inject + def sync_catch2(key2: HeaderKey) -> float: + return key2 + + assert sync_catch(headers={"key": 1}) == 1 + assert sync_catch2(headers={"key2": 1}) == 1 + + @serializer class TestSerializer: @pytest.mark.anyio