Skip to content

False positive W0108 (unnecessary lambda) #1709

@thehcma

Description

@thehcma

Steps to reproduce

lambda x: tuple(x)

Current behavior

This will be flagged as an unnecessary lambda, but note that, while we are converting something to a tuple, tuple while appearing to be a function, isn't. This is a type cast.

This comes up in practice, for instance, when using Pandas.

The following does not work (precisely because tuple is not a function):

grouped_df = df.groupby(group_by_attributes, as_index=False).aggregate(tuple)

The workaround:

grouped_df = df.groupby(group_by_attributes, as_index=False).aggregate(lambda x: tuple(x))

Leads to W0108 in pylint.

Expected behavior

No warning should be issued, by verifying the type of what is in the lambda. :)

pylint --version output

pylint 1.7.2,
astroid 1.5.3
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions