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

not (x in y) -> x not in y; not (x is y) -> x is not y #212

Open
JelleZijlstra opened this issue May 16, 2018 · 6 comments
Open

not (x in y) -> x not in y; not (x is y) -> x is not y #212

JelleZijlstra opened this issue May 16, 2018 · 6 comments
Labels
T: enhancement New feature or request T: style What do we want Blackened code to look like?

Comments

@JelleZijlstra
Copy link
Collaborator

This is a feature idea; feel free to declare it out of scope. Replace not (x in y) with x not in y and not (x is y) with x is not y.

@ambv
Copy link
Collaborator

ambv commented May 16, 2018

I agree with the premise but that wouldn't be compatible with --safe. Once --safe is no longer the default (that's when Black goes stable = way later in the year), we can introduce those sorts of transformations.

@ambv ambv added the T: enhancement New feature or request label May 16, 2018
@ambv ambv added this to To do in AST-unsafe changes May 9, 2019
@ambv
Copy link
Collaborator

ambv commented Mar 3, 2020

If you're willing to work on this, @JelleZijlstra, then it will go in. Otherwise we'll mark out of scope.

@merwok
Copy link

merwok commented Mar 3, 2020

One could argue that this is a matter of programming style, not aesthetic style, and that black’s domain is the latter only (I could be wrong).

Black’s goal is to remove the tedious explanations and arguments over aesthetics in code review, but there are other parts to a coding style guide / best practices defined by a company or group, and other tools can warn / change things that black doesn’t touch.

@Zac-HD
Copy link
Contributor

Zac-HD commented Aug 25, 2020

pybetter or shed --refactor do this, for what it's worth - see https://github.com/life4/awesome-python-code-formatters.

@JelleZijlstra JelleZijlstra added the T: style What do we want Blackened code to look like? label May 30, 2021
@felix-hilden
Copy link
Collaborator

felix-hilden commented Jan 17, 2022

I'd interpret Łukasz's comment to mean that --safe and --fast will eventually do different things, not just toggle the safety check. Maybe he meant that --safe would fail in this case, but I think disabling the relevant transforms would be better. This also relates to the AST changes discussion in #2150.

I know this is an old issue, but for my two cents I'd say that the change Jelle proposed sounds good, and so does the idea that --safe (or some other similar flag) will disable all formatting that changes AST. That would allow us to go further into formatting opinions, like docstrings for example.

@JelleZijlstra
Copy link
Collaborator Author

I'd interpret Łukasz's comment to mean that --safe and --fast will eventually do different things, not just toggle the safety check.

I don't know what Łukasz meant but I'd be opposed to that. --safe and --fast are orthogonal to formatting choices and shouldn't affect what formatting we do.

We could implement the suggestion from this issue and put a custom condition in the AST comparison logic that allows it, like we already do for a few other cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: enhancement New feature or request T: style What do we want Blackened code to look like?
Projects
Development

No branches or pull requests

5 participants