[Python] PEP8 multiline construct indentation

Discussão em 'Python' iniciado por Stack, Outubro 6, 2024.

  1. Stack

    Stack Membro Participativo

    According to PEP8#indentation "the closing brace/bracket/parenthesis on multiline constructs may be lined up under the first character of the line that starts the multiline construct, as in:"

    my_list = [
    1, 2, 3,
    4, 5, 6,
    ]
    result = some_function_that_takes_arguments(
    'a', 'b', 'c',
    'd', 'e', 'f',
    )


    My question is whether it's compliant with the PEP8 to have the closing bracket of the last function call in the chained assignments NOT to be on a separate line, as in my following code example:

    import os

    import pandas as pd
    import TimeSeriesClientBuilder

    ts = TimeSeriesClientBuilder.base(
    env='prd',
    mcp_token=os.getenv('TOKEN')
    ).add_pandas(
    ).build()

    def import_data_from_csv_v1(
    file_path: str
    ) -> pd.DataFrame:
    """Read a CSV file and return a DataFrame."""
    df = ts.read_csv(
    file_path, parse_dates=['date']
    ).set_index(
    'date'
    ).groupby(
    'region'
    ).sum()
    return df


    For me it looks more readable that way. Thanks for your advice.

    Continue reading...

Compartilhe esta Página