PyCQA / PyCQA/pycodestyle

E731: assignment of lambda is not detected if parenthesized

Open
#868 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.2k
Forks
754
PR merge metrics
No merged PRs in 30d

Description

$ cat foo.py
foo = lambda x: x
bar = (lambda x: x)
$ pycodestyle foo.py
foo.py:1:1: E731 do not assign a lambda expression, use a def

The second case is not detected. (A realistic case is when the parentheses are used for line continuation, e.g.

bar = (
    lambda ...: ...
)

)
Note that I agree that lambdas inside e.g. ternaries (#845) should not trigger a warning; this report is explicitly only for the case where a lambda is the sole thing being parenthesized.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the reported pycodestyle foo.py example and trace the E731 check that flags direct lambda assignments. Add coverage for a lambda that is the sole expression inside parentheses, including the line-continuation form, while preserving the behavior for lambdas inside ternaries; done means both cases are distinguished correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.