I have a case where I would like users of our package to be able to select from a list of options, for example
run_package(some_settings=("setting_1", "session_2", "setting_3"))
I have used a Tuple as the default argument on this function
def run_package(some_settings=("setting_1",):
...
To avoid the issue with having a mutable list as default argument. I prefer this form to the alternative:
def run_package(some_setting=None):
if some_setting is None:
# set default
some_setting = ["setting_1"]
as it is more explicit.
However, now I want to type this argument, e.g.
def run_package(some-settings: Tuple[Union[Literal["setting_1"], Literal["setting_2"], Literal["setting_3"]] = ("setting_1",)):
...
I am running into problems because, if I understand correctly, Tuple
type must be of fixed length as discussed here.
This makes sense as Tuple
is immutable. I guess this precludes its use as a default argument for a function as I have done? Are there any workarounds except for using None
as default?
Many Thanks