Closed scriptbotprime closed 3 months ago
We don't really do anything specific in the extension. All we do is return what black
provides after formatting. Also, note that even with the empty line, from python point of view the second print
is still part of the function block. The indentation on the print
line matters not the empty line.
So here both print
s are part of my_func
(note that there is no indentation on the empty line):
For second print to not be part of my_func
it should look like this:
You can enable verbose logging by setting "black-formatter.trace.server": "verbose"
in your user settings, and this will generate more detailed logs including the diff that is being applied to your code, and output from black itself. That should give more clues on what is going on.
Got the logs my self:
2024-03-20 12:57:25.606 [info] file:///c%3A/GIT/demo/diff_test/format_Test.py :
****************************************************************************************************
def my_func():
print("first part")
print("second part")
****************************************************************************************************
Black it self is returning this exact string:
Input: def my_func():\n print(\"first part\")\n \n print(\"second part\")\n
Output: def my_func():\n print(\"first part\")\n\n print(\"second part\")\n
As you can see in the output black
has removed the
empty line.
In a situation like this:
the plugin removes the identation of the "empty" line. Therefore the interpreter does not consider the second print statement as part of the function.