Hi there!!
I want to implement a dagger function in the python SDK where the dagger function return type is a base class and it returns a derived class that implements or modifies the base method.
- Abstract class implementation
Code example:
from abc import ABC, abstractmethod
import dagger
@dagger.object_type
class TestA(ABC):
@dagger.function
@abstractmethod
def test(self) -> str: ...
@dagger.object_type
class TestI(TestA):
@dagger.function
def test(self) -> str:
return "asd"
@dagger.object_type
class MyModule:
"""MyModule class."""
@dagger.function
def test(self) -> TestA:
return TestI()
I'm calling the dagger cli like this: dagger call test test
I'm getting the following error which is quite explanatory: Failed to instantiate TestA: invalid type (Can't instantiate abstract class TestA without an implementation for abstract method 'test')
- Derived class
Code example:
@dagger.object_type
class TestA:
@dagger.function
def test(self) -> str:
return "test_a"
@dagger.object_type
class TestI(TestA):
@dagger.function
def test(self) -> str:
test_a = super().test()
return test_a + "-" + "test_i"
@dagger.object_type
class MyModule:
"""MyModule class."""
@dagger.function
def test(self) -> TestA:
return TestI()
I'm calling the dagger cli like this: dagger call test test
It's returning test_a instead of test_a-test_i
Is it possible to set in a @dagger.function a return base class or protocol and return a derived class in the implementation?