I tried to make my function-description look beautiful but it didn't work. The problem is that I have two types of returns: a list and a string. Then you hover on functions vscode shows the returns of the functions like this. I found out that you can define one type of return using this example (-> str):
def function(x, y) -> str:
string = "test"
return string
But let's say I have tow diffrent return in my code:
def function(x, y):
if x == 1:
string = "test"
return string
else:
list = [1, 2]
return list
How to assign two different types of returns to that function? here is another example
Union[str, list]in the first place. (As an aside, docstrings are not involved here at all.)Union[str, list]but it is a bad idea to have a function that returns one of two unrelated types - that will complicate all the other code that has to call that function. Avoiding that will probably lead to a better design.