Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black not respecting fluent interfaces with parenthesis #2808

Closed
risoms opened this issue Jan 25, 2022 · 2 comments
Closed

Black not respecting fluent interfaces with parenthesis #2808

risoms opened this issue Jan 25, 2022 · 2 comments
Labels
F: linebreak How should we split up lines? F: linetoolong Black makes our lines too long R: duplicate This issue or pull request already exists T: bug Something isn't working

Comments

@risoms
Copy link

risoms commented Jan 25, 2022

Describe the bug

Black doesn't seem to respect fluent interfaces with parenthesis if the object isn't callable

To Reproduce
For example, when using a pytest mocker.

import pytest
import Session
def test_session(mocker):
    session = mocker.patch("Session")
    a = (
        session.query
            .return_value
            .filter
            .return_value
            .filter
            .return_value
            .filter
            .return_value
            .distinct
            .return_value
            .order_by
            .return_value
            .all
            .return_value
    )

This is converted to:

import pytest
import Session
def test_session(mocker):
    session = mocker.patch("Session")
    a = session.query.return_value.filter.return_value.filter.return_value.filter.return_value.distinct.return_value.order_by.return_value.all.return_value

Which causes a line-length error.

Expected behavior

Handling similar to this

import pytest
import Session
def test_session(mocker):
    session = mocker.patch("Session")
    a = (
        session.query
            .return_value
            .filter
            .return_value
            .filter
            .return_value
            .filter
            .return_value
            .distinct
            .return_value
            .order_by
            .return_value
            .all
            .return_value
    )

Environment

  • Black's version: main
  • OS and Python version: MacOS 2.0.1 (21A559)/Python 3.7.6

Additional context

@risoms risoms added the T: bug Something isn't working label Jan 25, 2022
@felix-hilden
Copy link
Collaborator

Thanks for submitting this! It's likely related to #571, but let's see. In the meantime, here's a playground link with some variations on this.

@felix-hilden felix-hilden added the F: linebreak How should we split up lines? label Jan 31, 2022
@felix-hilden
Copy link
Collaborator

Ah, it seems to be a duplicate of #510. Let's continue the discussion there.

@felix-hilden felix-hilden added F: linetoolong Black makes our lines too long R: duplicate This issue or pull request already exists labels Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: linebreak How should we split up lines? F: linetoolong Black makes our lines too long R: duplicate This issue or pull request already exists T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants