Long return type hint and pep8

Viewed 1371

I have a function that raises an E501 line too long (86 > 79 characters) warning when running pycodestyle.

def my_function(arg1: list = None) -> Tuple[pd.DataFrame, pd.DataFrame, pd.Dataframe]:
    # do stuff
    return df1, df2, df3

What is the best solution for formatting long return type hints (preferably without changing the format of the arguments? e.g.

def my_function(arg1: list = None) -> Tuple[pd.DataFrame,
                                            pd.DataFrame,
                                            pd.Dataframe]:
4 Answers

How about you use black. This will automatically format the code for you. Keep it mind to have same line lengths for both black and pycodestyle

You could try \:

def my_function(arg1: list = None)\
        -> Tuple[pd.DataFrame, pd.DataFrame, pd.Dataframe]:

Put the closing parenthesis and the return type hint on the next line:

def my_function(arg1: list = None
    ) -> Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]:
    # do stuff
    return df1, df2, df3

Use type aliases.

Dataframes = Tuple[pd.DataFrame, pd.DataFrame, pd.Dataframe]

def my_function(arg1: list = None) -> Dataframes:
# do stuff
return df1, df2, df3
Related