Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Handling of single line function definitions #277

ncoghlan opened this Issue · 4 comments

3 participants


To avoid the practice of assigning lambda expressions to names, PEP 8 now includes the guideline "Always use a def statement instead of an assignment statement that binds a lambda expression directly to a name."

Currently, the PEP 8 approved style for single line functions definitions generates an error, but the disallowed style is accepted:

$ cat >
def f(): pass
f = lambda: None
$ pep8 E701 multiple statements on one line (colon)

It would be better if there was an exception to E701 for "def" statements, and a new rule to complain about having a lambda definition as the sole expression on the right hand side of an assignment statement.


I've created a separate branch for this feature.

It passes the tests.

@florentx florentx added the feature label
@florentx florentx added this to the 1.6 milestone

I've merged this branch in trunk, with new codes E704 and E731.


@florentx florentx closed this

FWIW lambdas with names are useful in tests, for instance when replacing methods with stubs (using pytest.monkeypatch and pretend.stub in my case).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.