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

INTERNAL ERROR: Black produced different code on the second pass of the formatter #1934

Closed
SamuelMarks opened this issue Jan 18, 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

@SamuelMarks
Copy link

Describe the bug A clear and concise description of what the bug is.
Looks like my little debug message broke black

To Reproduce Steps to reproduce the behavior:

Mode(target_versions=set(), line_length=88, string_normalization=True, experimental_string_processing=False, is_pyi=False)
--- source
+++ first pass
@@ -50,16 +50,23 @@
         for name in other_params.keys() & target_params.keys():
             if not target_params[name].get("doc") and other_params[name].get("doc"):
                 target_params[name]["doc"] = other_params[name]["doc"]
             if target_params[name].get("typ") is None and other_params[name].get("typ"):
                 target_params[name]["typ"] = other_params[name]["typ"]
-            if (
-                target_params[name].get("default") in (None, "None", NoneStr)
-                and other_params[name].get("default") not in (None, "None", NoneStr)
-            ):
-                print("setting", name, "from", target_params[name].get("default"),
-                      "to", other_params[name]["default"])
+            if target_params[name].get("default") in (
+                None,
+                "None",
+                NoneStr,
+            ) and other_params[name].get("default") not in (None, "None", NoneStr):
+                print(
+                    "setting",
+                    name,
+                    "from",
+                    target_params[name].get("default"),
+                    "to",
+                    other_params[name]["default"],
+                )
                 target_params[name]["default"] = other_params[name]["default"]
 
         for name in other_params.keys() - target_params.keys():
             target_params[name] = other_params[name]
 
@@ -206,11 +213,11 @@
         ):
             del intermediate_repr["returns"]["return_type"]["typ"]
         intermediate_repr["returns"]["return_type"]["default"] = (
             lambda default: "({})".format(default)
             if isinstance(return_ast.value, Tuple)
-               and (not default.startswith("(") or not default.endswith(")"))
+            and (not default.startswith("(") or not default.endswith(")"))
             else (
                 lambda default_: default_
                 if isinstance(
                     default_, (str, int, float, complex, ast.Num, ast.Str, ast.Constant)
                 )
--- first pass
+++ second pass
@@ -50,15 +50,19 @@
         for name in other_params.keys() & target_params.keys():
             if not target_params[name].get("doc") and other_params[name].get("doc"):
                 target_params[name]["doc"] = other_params[name]["doc"]
             if target_params[name].get("typ") is None and other_params[name].get("typ"):
                 target_params[name]["typ"] = other_params[name]["typ"]
-            if target_params[name].get("default") in (
-                None,
-                "None",
-                NoneStr,
-            ) and other_params[name].get("default") not in (None, "None", NoneStr):
+            if (
+                target_params[name].get("default")
+                in (
+                    None,
+                    "None",
+                    NoneStr,
+                )
+                and other_params[name].get("default") not in (None, "None", NoneStr)
+            ):
                 print(
                     "setting",
                     name,
                     "from",
                     target_params[name].get("default"),
 

Expected behavior A clear and concise description of what you expected to happen.

Environment (please complete the following information):

  • Version: 20.8b1
  • OS and Python version: 3.8.7 on macOS 11.1

Does this bug also happen on master? To answer this, you have two options:

Yes

https://black.now.sh/?version=master,&state=_Td6WFoAAATm1rRGAgAhARYAAAB0L-Wj4ASqAXBdAD2IimZxl1N_WlkPinBFoPfEOxi8uWdJT0UKgWokyUrNuO0qdZcKgnPix9WX_wtYJQ_yJdfS_HtV0O6kBTwqxG3Z4TFDXftpWwHL0Q0lWBfnA7e5tTxcOnCzObYytn70Oj4WVpxKHlzCF-P-mM-3So-Xij3o7EvB3Q7buc9DuVgPMsHd2e2x4qKyZDHJlJTKAPHCkZG5gzyTQtpTzt0_1Du1ATsZeGB6935-MTs9a7eOSeL73Or4SKBGdEeAJLKRsYh6zjNw56uozSOyhvXvYg0SKdBO-dDJZQ0-Ocsg3lu6a7289J2j03ofJWio8zgPGX1YBS0uC_eXiY9CQtuUHsYuTAFMXL_E-mPTWYIoxkMJdASEfEmfBB1jXche7ejwxtU2Maou94ik-vd5vexmrYJ7jNO5GkaGYtRAfcq-ZVavvkwHOBEm3j0EaCdOzv1PicZhAf2A44ITlf8Zd5VZ7l1Cmt2GSm-L2cTBd66T7sIAAAQ-A2KkEU1oAAGMA6sJAAAl3zx4scRn-wIAAAAABFla

Additional context Add any other context about the problem here.

Code from the hosted black:

from operator import itemgetter


def f(target, other, NoneStr = None):
    if not target["params"]:
        target["params"] = other["params"]
    elif other["params"]:
        target_params, other_params = map(itemgetter("params"), (target, other))

        for name in other_params.keys() & target_params.keys():
            if not target_params[name].get("doc") and other_params[name].get("doc"):
                target_params[name]["doc"] = other_params[name]["doc"]
            if target_params[name].get("typ") is None and other_params[name].get("typ"):
                target_params[name]["typ"] = other_params[name]["typ"]
            if (
                target_params[name].get("default") in (None, "None", NoneStr)
                and other_params[name].get("default") not in (None, "None", NoneStr)
            ):
                print("setting", name, "from", target_params[name].get("default"),
                      "to", other_params[name]["default"])
                target_params[name]["default"] = other_params[name]["default"]
@SamuelMarks SamuelMarks added the T: bug Something isn't working label Jan 18, 2021
@ichard26 ichard26 added the C: unstable formatting Formatting changed on the second pass label Jan 18, 2021
@mvolfik
Copy link

mvolfik commented Feb 22, 2021

Likely a duplicate of #1629 , as this file works after applying #1958

@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