google / yapf

A formatter for Python files
Apache License 2.0
13.78k stars 892 forks source link

yapf formatting differs based on Python 3 version #696

Open imphil opened 5 years ago

imphil commented 5 years ago

I have the following code:

class A:
    def __init__(self, *extras):
        super().__init__(
            *chain((AbcdEfghij, AbcDef, AbcdEfghiJklmnopqr), extras))

Running yapf master e43ad9d/0.26.0/0.25.0 on Python 3.7.2 gives the following output:

$ yapf --style=pep8 -d testfile.py
--- testfile.py (original)
+++ testfile.py (reformatted)
@@ -1,4 +1,4 @@
 class A:
     def __init__(self, *extras):
-        super().__init__(
-            *chain((AbcdEfghij, AbcDef, AbcdEfghiJklmnopqr), extras))
+        super().__init__(*chain((AbcdEfghij, AbcDef,
+                                 AbcdEfghiJklmnopqr), extras))

Running yapf master e43ad9d/0.26.0/0.25.0 on Python 3.5.2 (Ubuntu 16.04 default) gives the following output:

$ yapf --style=pep8 -d testfile.py
$ echo $?
0

We expect users to run yapf locally and we run it in CI. Having different formatting requirements between a local runs and CI is very unfortunate for us.

Notes:

bwendling commented 5 years ago

Interesting. It of course shouldn't make a difference. I'll see what's up.

rory-ye-nv commented 5 years ago

I have the same problem, for yapf in python 3 and python 2, both with google style.

15:56:14 find . -name '*.py' -print0 | xargs -0 yapf --diff
15:56:40 --- ./aws/emr/s3/steps/download-artifact-new.py    (original)
15:56:40 +++ ./aws/emr/s3/steps/download-artifact-new.py    (reformatted)
15:56:40 @@ -33,8 +33,8 @@
15:56:40          # the path is allowed to contain variables like:
15:56:40          # {artifact_name}, {artifact_version}, etc.
15:56:40          # e.g. /{artifact_name}/{artifact_version}
15:56:40 -        self.artifact_path = args.artifact_path.format(
15:56:40 -            **args.__dict__).strip('/')
15:56:40 +        self.artifact_path = args.artifact_path.format(**args.__dict__).strip(
15:56:40 +            '/')
15:56:40          self.artifact_name = args.artifact_name
15:56:40          self.package_type = args.package_type
15:56:40          self.artifact_version = args.artifact_version
15:56:40 --- ./aws/emr/s3/steps/download-artifact.py    (original)
15:56:40 +++ ./aws/emr/s3/steps/download-artifact.py    (reformatted)
15:56:40 @@ -32,8 +32,8 @@
15:56:40          # the path is allowed to contain variables like:
15:56:40          # {artifact_name}, {artifact_version}, etc.
15:56:40          # e.g. /{artifact_name}/{artifact_version}
15:56:40 -        self.artifact_path = args.artifact_path.format(
15:56:40 -            **args.__dict__).strip('/')
15:56:40 +        self.artifact_path = args.artifact_path.format(**args.__dict__).strip(
15:56:40 +            '/')
15:56:40          self.artifact_name = args.artifact_name
15:56:40          self.package_type = args.package_type
15:56:40          self.artifact_version = args.artifact_version