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 ") :" #1588

Closed
ghost opened this issue Aug 11, 2020 · 3 comments · Fixed by #1655
Closed

Internal Error ") :" #1588

ghost opened this issue Aug 11, 2020 · 3 comments · Fixed by #1655
Labels
C: unstable formatting Formatting changed on the second pass T: bug Something isn't working

Comments

@ghost
Copy link

ghost commented Aug 11, 2020

The formatter notices this bug itself, and politely asked me to file an issue:

INTERNAL ERROR: Black produced different code on the second pass of the formatter.  
Please report a bug on https://github.com/psf/black/issues.

Here's a repo:

  1. take this file
very_long_variable_name = 0
very_very_long_variable_name = 1
extraordinarily_long_variable_name = 2

if assignment_expression := very_long_variable_name + very_very_long_variable_name > extraordinarily_long_variable_name:
    print("fubar")
  1. format it, and get the error with the following log
--- source
+++ first pass
@@ -1,8 +1,10 @@
-
 very_long_variable_name = 0
 very_very_long_variable_name = 1
 extraordinarily_long_variable_name = 2
 
-if assignment_expression := very_long_variable_name + very_very_long_variable_name > extraordinarily_long_variable_name:
+if (
+    assignment_expression := very_long_variable_name + very_very_long_variable_name
+    > extraordinarily_long_variable_name
+):
     print("fubar")
 
--- first pass
+++ second pass
@@ -3,8 +3,8 @@
 extraordinarily_long_variable_name = 2
 
 if (
     assignment_expression := very_long_variable_name + very_very_long_variable_name
     > extraordinarily_long_variable_name
-):
+) :
     print("fubar")

  • Version: black == 19.10b0
  • OS and Python version: Linux/Python 3.8.5
@ghost ghost added the T: bug Something isn't working label Aug 11, 2020
@ghost ghost changed the title Internal Error: Assignment expressions? Internal Error ") :" Aug 11, 2020
@ichard26
Copy link
Collaborator

ichard26 commented Aug 11, 2020

Seems to be resolved on master?

No :(

(black-rHKUX7ap) R:\Programming\black>type test.py
very_long_variable_name = 0
very_very_long_variable_name = 1
extraordinarily_long_variable_name = 2

if assignment_expression := very_long_variable_name + very_very_long_variable_name > extraordinarily_long_variable_name:
    print("fubar")

(black-rHKUX7ap) R:\Programming\black>black test.py
error: cannot format test.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: C:\Users\User\AppData\Local\Temp\blk_hpuu4wvb.log
Oh no! 💥 💔 💥
1 file failed to reformat.

That's an UI issue with that site. It runs with --fast which is rarely used as --safe is the default. Ironically, running with --fast in this case was better than running with --safe but in most cases you should use --safe as it checks that it isn't producing bad code.

Edit: here's a good example of why you shouldn't use --fast

@ichard26 ichard26 added the C: unstable formatting Formatting changed on the second pass label Aug 11, 2020
@hugovk
Copy link
Contributor

hugovk commented Aug 12, 2020

Hmm, I was going to make a PR to Black Playground to remove --fast, but couldn't find it. Here's the config it uses:

https://github.com/jpadilla/black-playground/blob/439d825ae07fc478e0bce671973d295f46691884/api/app.py#L85-L90

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 T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants