Given the following, factory methods fail to produce the expected outcome, and instead raise the NotImplementedError exception.
class Dep:
def __init__(_, value: str):
...
TypeA = Annotated[Dep, "type_a"]
TypeB = Annotated[Dep, "type_b"]
class Fetcher:
def __init__(_, dep: Dep):
...
def factory(scope, dep_type) -> Dep:
if dep_type == TypeA:
value = "a"
elif dep_type == TypeB:
value = "b"
else:
raise NotImplementedError(f"Unknown type: {dep_type}")
return Dep(value)
container.add_transient_by_factory(factory, TypeA)
container.add_transient_by_factory(factory, TypeB)
container.add_transient(Fetcher)
fetcher = container.get(Fetcher)