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

Chained method calls quite unreadable #323

Closed
dcramer opened this issue Jun 8, 2018 · 4 comments
Closed

Chained method calls quite unreadable #323

dcramer opened this issue Jun 8, 2018 · 4 comments

Comments

@dcramer
Copy link

dcramer commented Jun 8, 2018

Black version: 18.6b2

I find this vomit-worthy:

--- a/tests/zeus/artifacts/test_checkstyle.py
+++ b/tests/zeus/artifacts/test_checkstyle.py
@@ -12,11 +12,9 @@ def test_result_generation(sample_checkstyle, default_job):
     handler.process(fp)

     results = list(
-        StyleViolation.query.unrestricted_unsafe().filter(
-            StyleViolation.job_id == default_job.id
-        ).order_by(
-            StyleViolation.filename.asc(), StyleViolation.message.asc()
-        )
+        StyleViolation.query.unrestricted_unsafe()
+        .filter(StyleViolation.job_id == default_job.id)
+        .order_by(StyleViolation.filename.asc(), StyleViolation.message.asc())
     )
@dcramer
Copy link
Author

dcramer commented Jun 8, 2018

Recommendation:

  • Keep them newline separated similar to the original (probably hard)
  • Indent each follow-up line
  • ???

@ambv
Copy link
Collaborator

ambv commented Jun 8, 2018

That's intentional and an implementation of #67. Read there for specifics.

Specifically for use like yours (with ORMs), it's cleaner to specify subsequent calls with a leading dot. It's symmetrical to, say, list comprehensions:

results = [
    element
    for element in collection
    if X
    if Y
]

@dcramer
Copy link
Author

dcramer commented Jun 8, 2018

Ok fine :(

FWIW JS has this everywhere, and anecdotally I believe the standard is indent for following lines and it has made it quite readable.

@dcramer dcramer closed this as completed Jun 8, 2018
@ambv
Copy link
Collaborator

ambv commented Jun 8, 2018

The indentation in JavaScript is to that you can see where the chain ends. In Python we require parentheses around the call chain so we don't need additional indentation to make it explicit what's going on. We don't indent other operators (+/-/and/or and so on) either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants