Manuel
Manuel

Reputation: 843

Unused variable problematic for PEP8 standard?

I am currently trying to get my python code to be compatible to PEP8. For the following code pylint tells me that the type_list variable in filter_not is problematic because it is never used. While this is of course true I am not sure how to fix this. Is there a better way to do this or is this just a false positive?

Note that the code below is just an extract. There are actually far more functions in there which the switcher_filter handles. So an regular if statement would get far to big. Also I am not using an enum for the switcher option as the main function is called from outside and I do not want to import the enum into every file calling the module.

def filter_by_x(df_input, type_list):
    return df_input[lambda df: df["x"].isin(type_list)]

def filter_not(df_input, type_list):
    return df_input

switcher_filter = {
    'not':  filter_not(removed_duplicates_df, type_list),
    'x': filter_by_x(removed_duplicates_df, type_list)

filtered_df = switcher_filter.get(filterby)
}

Upvotes: 0

Views: 377

Answers (1)

Pierre.Sassoulas
Pierre.Sassoulas

Reputation: 4282

For your example why not do this:

def filter_by_x(df_input, type_list):
    return df_input[lambda df: df["x"].isin(type_list)]

def filter_not(df_input):
    return df_input

switcher_filter = {
    'not':  filter_not(removed_duplicates_df),
    'x': filter_by_x(removed_duplicates_df, type_list)
    filtered_df = switcher_filter.get(filterby)
}

In the general case there's a setting in pylint to ignore some variable that you know are unused. Namely a leading underscore, a leading unused or a leading ignored (by default).

This is configurable with:

# Argument names that match this expression will be ignored.
ignored-argument-names=_.*|^ignored_|^unused_

Upvotes: 1

Related Questions