question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Knob to allow alternative formatting of call chains

See original GitHub issue

In addition to the standard method of getting call chains formatted like this:

rawKPIs = KPIsSession.query(
    KPI.name, KPI.value, KPI.created
).filter(KPI.entryId == entryID).filter(KPI.subsetId is None).filter(
    KPI.created >= fromUnixTimestamp(fromTimestamp)
).filter(KPI.created <= fromUnixTimestamp(toTimestamp)).filter(
    func.unix_timestamp(KPI.created) % moduloSelector == 0
).order_by(KPI.name, KPI.created).all()

Allow formatting as:

rawKPIs = \
    KPIsSession.query(
        KPI.name, KPI.value, KPI.created
    ).filter(
        KPI.entryId == entryID
    ).filter(    
        KPI.subsetId is None
    ).filter(
        KPI.created >= fromTimestamp
    ).filter(
        KPI.created <= toTimestamp
    ).filter(
        KPI.created % moduloSelector == 0
    ).order_by(
        KPI.name, KPI.created
    ).all()

or:

rawKPIs = \
    KPIsSession.query(KPI.name, KPI.value, KPI.created) \
    .filter(KPI.entryId == entryID) \
    .filter(KPI.subsetId is None) \
    .filter(KPI.created >= fromTimestamp) \
    .filter(KPI.created <= toTimestamp) \
    .filter(KPI.created % moduloSelector == 0) \
    .order_by(KPI.name, KPI.created) \
    .all()

This makes the code more readable and stack traces clearer. (due to line number)

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:8
  • Comments:15 (2 by maintainers)

github_iconTop GitHub Comments

20reactions
qsorixcommented, Jan 4, 2018

Hi. I’m confused by the comments here. Assuming I already have ( ) surrounding my chained call, is it possible to configure yapf to do this?

rawKPIs = (
    KPIsSession.query(KPI.name, KPI.value, KPI.created) 
    .filter(KPI.entryId == entryID) 
    .filter(KPI.subsetId is None) 
    .filter(KPI.created >= fromTimestamp) 
    .filter(KPI.created <= toTimestamp) 
    .filter(KPI.created % moduloSelector == 0) 
    .order_by(KPI.name, KPI.created) 
    .all()
)

Right now my yapf (0.20) turns that code into this, which is far from what I want 😉.

rawKPIs = (
    KPIsSession.query(KPI.name, KPI.value, KPI.created)
    .filter(KPI.entryId == entryID).filter(KPI.subsetId is None)
    .filter(KPI.created >= fromTimestamp).filter(KPI.created <= toTimestamp)
    .filter(KPI.created % moduloSelector == 0).order_by(KPI.name,
                                                        KPI.created).all()
)

I have a lot of chained calls in my pyspark application, and poor formatting of those is the one reason preventing me from using yapf. Ideally I’d like something like in the first quoted fragment.

8reactions
advance512commented, Dec 13, 2016

Another idea is adding parenthesis, but this is obviously more problematic:

rawKPIs = (
    KPIsSession.query(KPI.name, KPI.value, KPI.created) 
    .filter(KPI.entryId == entryID) 
    .filter(KPI.subsetId is None) 
    .filter(KPI.created >= fromTimestamp) 
    .filter(KPI.created <= toTimestamp) 
    .filter(KPI.created % moduloSelector == 0) 
    .order_by(KPI.name, KPI.created) 
    .all()
)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Inconsistent formating of long method call chains #3157 - GitHub
I turned out to be really hard to get consistently great formatting for chains. Although this is not great, I think the alternatives...
Read more >
Yocto-Knob : User's guide
The Yocto-Knob is a 45x20mm electronic module which allows you to measure the state of switches, push buttons, or potentiometers.
Read more >
axblack - PyPI
This is a forked alternative to the official black formatter, ... call chains are now formatted according to the fluent interfaces style (#67)....
Read more >
Change a control's Bitmap at run time? [Archive] - Cockos ...
I have been thinking about this, too. It would allow for users to customize the knobs, and it would also allow for some...
Read more >
ASCII Protocol Manual - Zaber
If there is more than one device in a chain, sending the command /move abs 10000 will move all ... The axis is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found