-
Notifications
You must be signed in to change notification settings - Fork 6
Description
Currently, andi.plan() works by passing a function or class. This requires them to have their signatures already established:
class Valves:
pass
class Engine:
def __init__(self, valves: Valves):
self.valves = valves
class Wheels:
pass
class Car:
def __init__(self, engine: Engine, wheels: Wheels):
self.engine = engine
self.wheels = wheelsHowever, there are use cases where we might want to create different types of cars which means that the car signatures could be dynamic which is only determined during runtime.
For example, during runtime the car's wheels could be electric, or the wheels could become tank treads. We could solve this by defining an ElectricCar or TankCar. Yet, this solution doesn't cover all the other permutation of car types, especially when its signature changes if it adds an arbitrary amount of attachments:
engine: Engine, wheels: Wheels, top_carrier: RoofCarrierengine: Engine, wheels: Wheels, top_carrier: BikeRackengine: Engine, wheels: Wheels, back_carrier: BikeRack, top_carrier: RoofCarrier
We could list down all of the possible dependencies in the signature but that wouldn't be efficient since it takes some effort to fulfill all of them but at the end, only a handful of them will be used.
I'm proposing to update the API to allow such arbitrary signatures to used. This allows something like this to be possible:
def get_blueprint(customer_request):
results: Dict[str, Any] = {}
for i, dependency in enumerate(read_request(customer_request)):
results[f"arg_{i}"] = results
return results # something like {"arg_1": Engine, "arg_2": Wheels, "arg_3": BikeRack}
signature = get_blueprint(customer_request)
plan = andi.plan(
signature,
is_injectable=is_injectable,
externally_provided=externally_provided,
)andi.plan() largely remains the same except that it now supports a mapping representing any arbitrary function/class signature.