Skip to content

Issue with autoFormatOnSave and yapf #124

@DonJayamanne

Description

@DonJayamanne

From @dcramer on June 1, 2017 6:44

Environment data

VS Code version: 1.12.2 (tried Insiders as well)
Python Extension version: 0.6.4
Python Version: 2.7.13
OS and version: macOS Sierra 10.12.4

Actual behavior

Upon save it reformats the file, and does not appear to behave the same as yapf -i file.

For example, this content:

from __future__ import absolute_import

from django.db import models
from django.utils import timezone

from sentry.db.models import (BoundedBigIntegerField, FlexibleForeignKey,
                              Model, sane_repr)

When I hit save, it generates invalid Python:

from __future__ import absolute_import

from django.db import models
from django.utils import timezone

from sentry.db.models import (
    BoundedBigIntegerField, FlexibleForeignKey, Model, sane_repr
)
)

Expected behavior

The expected output should be:

from __future__ import absolute_import

from django.db import models
from django.utils import timezone

from sentry.db.models import (
    BoundedBigIntegerField, FlexibleForeignKey, Model, sane_repr
)

Steps to reproduce:

  • add editor.formatOnSave to workspace settings
  • save the file

Even when it doesnt incorrectly format the file into invalid Python, it doesnt seem to respect the configuration within setup.cfg (i still get different output from yapf -i).

Here is the changeset which we identified this behavior in:

getsentry/sentry@a2587aa

Settings

Your launch.json (if dealing with debugger issues):

Your settings.json:

{
    "files.exclude": {
        "**/*.pyc": true,
        "static": true,
        "node_modules": true,
        "src/sentry/static/dist": true,
        "env": true
    },
    "prettier.bracketSpacing": false,
    "prettier.singleQuote": true,
    "prettier.printWidth": 90,
    "eslint.options": {
        "configFile": ".eslintrc"
    },
    "[javascript]": {
        "editor.formatOnSave": true
    },
    "[json]": {
        "editor.formatOnSave": true
    },
    "editor.formatOnSave": true,
    "python.linting.pylintEnabled": false,
    "python.linting.flake8Enabled": true,
    "python.formatting.provider": "yapf",
    "python.pythonPath": "${env.WORKON_HOME}/sentry/bin/python"
}

Copied from original issue: DonJayamanne/pythonVSCode#992

Metadata

Metadata

Labels

area-formattingbugIssue identified by VS Code Team member as probable bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions