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

Comments interfering with fluent formatting #458

Open
max-sixty opened this issue Aug 17, 2018 · 3 comments
Open

Comments interfering with fluent formatting #458

max-sixty opened this issue Aug 17, 2018 · 3 comments
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. T: bug Something isn't working

Comments

@max-sixty
Copy link

Copied over from #379 (comment)

Without a comment, formatted with black (-l 79)

    return (
        df_day.assign(date=date, fund_ticker=ticker)
        .pipe(lambda x: x.loc[x["Shares"].notnull()])
        .assign(Shares=df_day["Shares"].astype("float64"))
    )

Adding a comment, before formatting

    return (
        df_day.assign(date=date, fund_ticker=ticker)
        .pipe(lambda x: x.loc[x["Shares"].notnull()])
        # arrives as int sometimes
        .assign(Shares=df_day["Shares"].astype("float64"))
    )

With a comment, after formatting with black:

    return (
        df_day.assign(date=date, fund_ticker=ticker).pipe(
            lambda x: x.loc[x["Shares"].notnull()]
        )
        # arrives as int sometimes
        .assign(Shares=df_day["Shares"].astype("float64"))
    )

Without thinking about the more general problem, the second example here is ideal - the comment can be within a fluent expression and wouldn't change the fluent expression formatting.

Thanks again for such an awesome library and vision!

Operating system: MacOS
Python version: 3.7
Black version: 18.6b4
Does also happen on master:

@ambv
Copy link
Collaborator

ambv commented Sep 26, 2018

I agree with you that comments should not break the flow of fluent interfaces. We'll address it next week.

@ambv ambv added T: bug Something isn't working F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. labels Sep 26, 2018
@ambv ambv added the stable label Mar 3, 2020
@ambv ambv added this to To Do in Stable release via automation Mar 3, 2020
@ambv
Copy link
Collaborator

ambv commented Mar 3, 2020

The problem is that the standalone comment "splits" the fluent interface so Black sees two periods before (and fluent interfaces are implemented to only apply for >2 periods), then a comment, and one after.

@ambv
Copy link
Collaborator

ambv commented Mar 3, 2020

See this Black playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. T: bug Something isn't working
Projects
No open projects
Stable release
  
To Do (nice to have)
Development

No branches or pull requests

3 participants