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

Black produced different code on the second pass of the formatter #2011

Closed
mikekeda opened this issue Feb 26, 2021 · 2 comments
Closed

Black produced different code on the second pass of the formatter #2011

mikekeda opened this issue Feb 26, 2021 · 2 comments
Labels
C: unstable formatting Formatting changed on the second pass R: duplicate This issue or pull request already exists T: bug Something isn't working

Comments

@mikekeda
Copy link

mikekeda commented Feb 26, 2021

Describe the bug
When I was using black to format a file I got a message:

error: cannot format athletes/core/tasks.py: INTERNAL ERROR: Black produced different code on the second pass of the formatter.  Please report a bug on https://github.com/psf/black/issues.  This diff might be helpful: /var/folders/v0/gbwcrbr93m55b70qt6cs2plr0000gn/T/blk_56ym5h4m.log

cat /var/folders/v0/gbwcrbr93m55b70qt6cs2plr0000gn/T/blk_56ym5h4m.log

Mode(target_versions=set(), line_length=88, string_normalization=True, experimental_string_processing=False, is_pyi=False)
--- source
+++ first pass
@@ -206,11 +206,14 @@
 
                     if not link:
                         link = td[i].select_one("span.vcard a")
 
                     if link and link.string in [
-                        "United States", "South Korea", "North Korea", "Ivory Coast"
+                        "United States",
+                        "South Korea",
+                        "North Korea",
+                        "Ivory Coast",
                     ] + list(COUNTRIES.values()):
                         continue  # it's not a athlete
 
                     full_link, status = validate_link_and_create_athlete(
                         link, site, cleaned_data
--- first pass
+++ second pass
@@ -205,16 +205,21 @@
                             link = link.find("a", recursive=False)
 
                     if not link:
                         link = td[i].select_one("span.vcard a")
 
-                    if link and link.string in [
-                        "United States",
-                        "South Korea",
-                        "North Korea",
-                        "Ivory Coast",
-                    ] + list(COUNTRIES.values()):
+                    if (
+                        link
+                        and link.string
+                        in [
+                            "United States",
+                            "South Korea",
+                            "North Korea",
+                            "Ivory Coast",
+                        ]
+                        + list(COUNTRIES.values())
+                    ):
                         continue  # it's not a athlete
 
                     full_link, status = validate_link_and_create_athlete(
                         link, site, cleaned_data
                     )

To Reproduce

  1. Take this file https://github.com/mikekeda/athletes/blob/59ed50ab330c4095c4de4e35a02b1f50fdbc6b05/core/tasks.py#L212
  2. Run Black on it black core/tasks.py
  3. See error

Expected behavior
I expected it to format the file without error.

Environment (please complete the following information):

  • Version: 20.8b1
  • OS and Python version: MacOS 11.2.1, Cpython 3.9.0

Does this bug also happen on master? To answer this, you have two options:
yes (latest master branch)

Additional context

@mikekeda mikekeda added the T: bug Something isn't working label Feb 26, 2021
@mberezin-r7
Copy link

Possible dupe #1629

@ichard26 ichard26 added the C: unstable formatting Formatting changed on the second pass label Feb 28, 2021
@ichard26 ichard26 added the R: duplicate This issue or pull request already exists label Apr 25, 2021
@ichard26
Copy link
Collaborator

Hello!

All reproduction cases in this issue format without error on master. The fixing commit was 8672af3 from PR GH-2126. I'll be marking this issue as a duplicate of GH-1629 since that's what GH-2126 aimed to fix and it's highly likely this issue falls under GH-1629.

Since we use the issue tracker as a reflection of what's on master, I'll be closing this issue. If you have any issues, especially with the new (but stable) output, please open a new issue. Oh and the fix should be available in a published release soon, see GH-2125 for more info.

Thank you for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: unstable formatting Formatting changed on the second pass 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