Riccardo Tesselli
04/12/2023, 1:20 PMclass A:
def __init__(self, secret: SecretStr):
self.secret = secret
...
@resource(config_schema={"secret": str})
def a(init_context: InitResourceContext):
return A(
secret=SecretStr(init_context.resource_config["secret"])
)
I would like to convert this to the new pythonic-style resources by doing this:
class A(ConfigurableResource):
secret: Any
@root_validator()
def to_secret_str(cls, values):
values["secret"] = SecretStr(values["secret"])
return values
This is the only way I’ve managed to make it work, even though ideally I’d prefer to do like:
class A(ConfigurableResource):
secret: SecretStr
but this fails because SecretStr
is not a valid Dagster type.
Is there another way to convert this resource into a Pythonic-style without using Any
? I don’t like using Any
because then my typing would be too generic and not useful at allben
04/14/2023, 9:58 PMSecretStr
to our list of improvements to make to the systemRiccardo Tesselli
04/18/2023, 8:22 AMSecretStr
, but I wonder how many more such cases there will be and so it is virtually impossible to manually add support for all of them. There will be a way to let the programmer decide which types to use in its own resources?ben
04/21/2023, 4:37 PMclass MyClient:
"""Client class with mutable state."""
def __init__(self, username: str, password: str):
self.username = username
self.password = password
self._cache = {}
...
class MyClientResource(ConfigurableResource):
username: str
password: str
def get_client(self):
return MyClient(self.username, self.password)