From 9433d442f87f2d3190440de68385c525f661697e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A4rsson?= Date: Fri, 9 Jan 2026 09:04:39 +0100 Subject: [PATCH] Add test for #303 --- injector_test.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/injector_test.py b/injector_test.py index 4591d86..e9f791f 100644 --- a/injector_test.py +++ b/injector_test.py @@ -17,7 +17,7 @@ import warnings from contextlib import contextmanager from dataclasses import dataclass -from typing import Any, NewType, Optional, Union +from typing import Any, Literal, NewType, Optional, Union if sys.version_info >= (3, 9): from typing import Annotated @@ -2246,3 +2246,14 @@ def provide_second(self) -> Annotated[str, 'second']: injector = Injector(module) assert injector.get(Annotated[str, 'first']) == 'Bob' assert injector.get(Annotated[str, 'second']) == 'Iger' + + +# Test for https://github.com/alecthomas/injector/issues/303 +@pytest.mark.skipif(sys.version_info < (3, 10), reason="Requires Python 3.10+") +def test_can_inject_dataclass_with_literal_value(): + @dataclass(slots=True) + class ServiceConfig: + environment: Literal["prod", "test"] = "test" + + injector = Injector() + assert injector.get(ServiceConfig).environment == "test"