'Type annotations: tuple type vs union type
def func(df_a: pd.DataFrame, df_b: pd.DataFrame) -> (pd.DataFrame, pd.DataFrame):
Pylance is advising to modify this line with two solution proposed. What would be the pros and cons of each one if there is any significant difference?
Tuple expression not allowed in type annotation
Use Tuple[T1, ..., Tn] to indicate a tuple type or Union[T1, T2] to indicate a union type
Solution 1:[1]
A union type wouldn't make sense here since the types are the same.
If you want to indicate that a tuple is being returned, you'd use Tuple[pd.DataFrame, pd.DataFrame] in older versions of Python, or tuple[pd.DataFrame, pd.DataFrame] in newer versions of Python. See here for more information.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Carcigenicate |
