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

Odd Formatting Bug #1523

Closed
ghost opened this issue Jun 28, 2020 · 5 comments
Closed

Odd Formatting Bug #1523

ghost opened this issue Jun 28, 2020 · 5 comments
Labels
R: duplicate This issue or pull request already exists T: bug Something isn't working

Comments

@ghost
Copy link

ghost commented Jun 28, 2020

To Reproduce Steps to reproduce the behavior:
Write this:

posts = [
    {
        "author": "CoreyMS",
        "title": "Blog Post 1",
        "content": "First post content",
        "date_posted": datetime.datetime.utcnow().strftime("%A, %x")
    },
    {
        "author": "CoreyMS",
        "title": "Blog Post 1",
        "content": "First post content",
        "date_posted": datetime.datetime.utcnow() + datetime.timedelta(3).strftime("%A, %x"),
    }
]

Press ctrl + s to save on vscode with black as the formatter (It does not matter if you do this or run black normally with black .
This happens:

posts = [
    {"author": "CoreyMS", "title": "Blog Post 1", "content": "First post content", "date_posted": datetime.datetime.utcnow().strftime("%A, %x")},
    {
        "author": "CoreyMS",
        "title": "Blog Post 1",
        "content": "First post content",
        "date_posted": datetime.datetime.utcnow() + datetime.timedelta(3).strftime("%A, %x"),
    },
]

Expected behavior:
It keeps that style instead of the (no-offence) ugly formatting

Environment:

  • Version: Master
  • OS and Python version: Kubuntu 20.04 LTS focal fossa (kde 5) with python 3.8.2

Does this bug also happen on master?
It does

Additional context:
Also with this, black is colliding with flake8. Black makes a code that looks like this:

example = {'one': 'first', 'two': 'second'}

To this:

example = {'one': 'first', 'two': 'second',}

(It adds the extra , at the end without a space)
This raises missing whitespace after ','flake8(E231)
Is there a configuration option to either add a space or just not have a trailing comma at the end? I tried to look up in the docs for such configuration option but failed to find it 😞
Additionally, I cannot see any configuration options in the docs that I can add in the configuration file

@ghost ghost added the T: bug Something isn't working label Jun 28, 2020
@mx-psi
Copy link

mx-psi commented Jun 28, 2020

If you add a trailing comma at the end of the date_posted field it should keep it as it is. The behavior is being worked on (see #1288) but that should work for now.

@ghost
Copy link
Author

ghost commented Jun 29, 2020

I tried to play with the styling on this dictionary and this is what I wanted:
image
But when I format it I get this:
image
Adding a trailing comma also does not fix this 😞

@mx-psi
Copy link

mx-psi commented Jun 29, 2020

Maybe I explained myself incorrectly. In your screenshots you are removing the trailing comma and adding one trailing comma at the end, while what I suggested was doing:

posts = [
    {
        "author": "CoreyMS",
        "title": "Blog Post 1",
        "content": "First post content",
        "date_posted": datetime.datetime.utcnow().strftime("%A, %x"),
    },
    {
        "author": "CoreyMS",
        "title": "Blog Post 1",
        "content": "First post content",
        "date_posted": datetime.datetime.utcnow() + datetime.timedelta(3).strftime("%A, %x"),
    }
]

which should keep the format.

@ghost
Copy link
Author

ghost commented Jun 29, 2020

Nothing changes, even if I copy the same exact code that you sent 😞

@ichard26
Copy link
Collaborator

ichard26 commented Jul 28, 2020

For clarity, the "magic trailing comma" feature doesn't work in nested collection literals yet. This falls under the scope of #1288 and there is already an issue filed for this bug: #1377.

@ichard26 ichard26 added the R: duplicate This issue or pull request already exists label Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R: duplicate This issue or pull request already exists T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants