Skip to content

C2801 False positive when __setitem__ appears in a lambda #8769

@asarkar

Description

@asarkar

Bug description

I have a function that accepts a lambda as follows:

zigzag(
        encoded_message,
        num_rails,
        lambda i, _: rail_lengths.__setitem__(i, rail_lengths[i] + 1)
)

pylint generates an error:

C2801: Unnecessarily calls dunder method __setitem__. Set item via subscript. (unnecessary-dunder-call)

But assignment isn’t valid in a lambda, so, the suggestion is incorrect.

Configuration

No response

Command used

pylint \
  --score n \
  --ignore-paths '^.*_test.py$' \
  --disable C0103,C0104,C0114,C0115,C0116 \
  "$basedir"/**/*.py

Pylint output

C2801: Unnecessarily calls dunder method __setitem__. Set item via subscript. (unnecessary-dunder-call)

Expected behavior

No error.

Pylint version

pylint 2.17.4
Python 3.11.3

OS / Environment

No response

Additional dependencies

No response

Metadata

Metadata

Assignees

Labels

Bug 🪲False Positive 🦟A message is emitted but nothing is wrong with the codeGood first issueFriendly and approachable by new contributors

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions