-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 code that is not equivalent to the source #3115
Comments
The "not equivalent to the source" is a safety check we perform to ensure we don't mess up your files, so it being pretty generic makes it pretty much impossible to narrow the problem down. Thank you for the log file though! Could you take the file and try to simplify it while preserving the error, so that you could share it with us? |
@felix-hilden Actually i find out what was going wrong: I add some An example: def test_a_random_test(self):
...
# some code
...
# fmt: off
# Insert here a very long series of slicing over a nested list (a graphql api response)
# fmt: off
# Insert here a very long series of slicing over a nested list (a graphql api response)
# fmt: off
# Insert here a very long series of slicing over a nested list (a graphql api response)
...
# some code
...
def test_later_added(self):
...
# some code
... Removing/adding the You can close this issue if you want, as i identify what was going wrong. Thanks ! |
A minimal example def first(self):
# fmt: off
...
def second(self):
... Black produces def first(self):
# fmt: off
...
def second(self):
... This is wrong |
AST diff--- src
+++ dst
@@ -29,54 +29,54 @@
None, # NoneType
value=
Ellipsis, # ellipsis
) # /Constant
) # /Expr
+ FunctionDef(
+ args=
+ arguments(
+ args=
+ arg(
+ annotation=
+ None, # NoneType
+ arg=
+ 'self', # str
+ type_comment=
+ None, # NoneType
+ ) # /arg
+ defaults=
+ kw_defaults=
+ kwarg=
+ None, # NoneType
+ kwonlyargs=
+ posonlyargs=
+ vararg=
+ None, # NoneType
+ ) # /arguments
+ body=
+ Expr(
+ value=
+ Constant(
+ kind=
+ None, # NoneType
+ value=
+ Ellipsis, # ellipsis
+ ) # /Constant
+ ) # /Expr
+ decorator_list=
+ name=
+ 'second', # str
+ returns=
+ None, # NoneType
+ type_comment=
+ None, # NoneType
+ ) # /FunctionDef
decorator_list=
name=
'first', # str
returns=
None, # NoneType
type_comment=
None, # NoneType
) # /FunctionDef
- FunctionDef(
- args=
- arguments(
- args=
- arg(
- annotation=
- None, # NoneType
- arg=
- 'self', # str
- type_comment=
- None, # NoneType
- ) # /arg
- defaults=
- kw_defaults=
- kwarg=
- None, # NoneType
- kwonlyargs=
- posonlyargs=
- vararg=
- None, # NoneType
- ) # /arguments
- body=
- Expr(
- value=
- Constant(
- kind=
- None, # NoneType
- value=
- Ellipsis, # ellipsis
- ) # /Constant
- ) # /Expr
- decorator_list=
- name=
- 'second', # str
- returns=
- None, # NoneType
- type_comment=
- None, # NoneType
- ) # /FunctionDef
type_ignores=
) # /Module
\ No newline at end of file |
I think it's a problem with block statements in general, the issue also occurs with the following if True:
# fmt: off
...
print(2) if True:
...
#fmt: off
print(4)
print(2) |
Hello ! I'm facing an issue while trying to use black to lint a file.
When trying to lint my piece of code (either with pre-commit or running black itself), the below error happen. Unfortunately, i can't provide any example as it's not my property.
The resulting error is:
You can find the log content here: https://privatebin.net/?dfa3a27759345ea2#CehPbuNtkh7aqgdpn5WWhXdVs2zD1fCQVoAiG2SMp1J5
Environment
The text was updated successfully, but these errors were encountered: