How can I combine the following:
def function(arg1, arg2: str):...
and
def function(arg1, arg2={}):...
?
In the first case, I NEED to enter two arguments. But it can be possible, that arg2
is not given to the function (-> error). I would like to have the second option but additionally with : str
, so that I HAVE to give a string as arg2
to the function IF I like to use arg2
.
I tried something like
def function(arg1, arg2={}: str):...
but it did not work. Of course, there is the possibility to check the type inside of the function, that is clear and throw an exception. That is clear. To have a compact solution as with arg: <type>
in the function call is elegant.