psf / psf/black

Line too long: Lambda with many parameters

Open
#809 17 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

F: linetoolong T: style
Dominant language
Python
Stars
41.8k
Forks
2.9k
Avg merge
5d 6h
Merged PRs (30d)
9

Description

Operating system: macos 10.14.4
Python version: 3.6.7
Black version: 19.3b0
Does also happen on master: Yes

We have an interesting way to create pytest fixtures. We've created a function called lambda_fixture() that lets us skip most of the boilerplate issues when creating fixtures. It looks something like this:

my_user = lambda_fixture(lambda user_factory: user_factory(name='Mike'))

That's all well and good, but sometimes these things can have a pretty long list of parameters. Unfortunately, black doesn't handle this very well:

my_long_variable_name = lambda_fixture(
    lambda fixture_1, another_long_fixture_name, some_fixture_factory, some_long_fixture_name_again, short, wow, long_fixture_name: some_fixture_factory.create_batch(
        size=10,
        something=short,
        something_else=long_fixture_name,
    )
)

It would be nice to have black wrap and/or chop down the lambda parameter list. Bonus points if the indent of the wrap/chop is different than the indent of the body of the lambda.

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

Use the long-lambda example in the issue as the reproduction case. No files or tests are named, so first locate Black's existing lambda-formatting logic and its related tests, then compare current output with the requested parameter wrapping or chopping. Done means long lambda parameter lists format consistently without disrupting the lambda body.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.