ModularM
Modular2y ago
16 replies
artemiogr97

Optional string argument

Is there a simple way to create a function that takes an optional String argument with no default value (assigned to None) ? I tried the following:
fn my_func(my_string: Optional[String] = None)-> String:
    ...

this works for a String but calling the function with a StringLiteral does not: my_func("my_string") gives the following error invalid call to 'my_func': argument #0 cannot be converted from 'StringLiteral' to 'Optional[String]'

I guess one way to make it work for now is to use a default value as follows:
fn my_func(my_string: String = "my_default_string")-> String:
    ...

But this does not allow to distinguish between a bad input and an empty imput
Was this page helpful?