Using normal mode in yapf adds new lines to the formatted code, but when using the diff option new lines at the end of file are not included in the patch. Maybe the diff is generated based on unformatted code that has EOF newline added.
You can try it here https://replit.com/@replitfaris/yapf-newline-patch
source:
from yapf.yapflib.yapf_api import FormatCode
unformatted_code = "f(a=1, b=2)"
print("unformatted code")
print(repr(unformatted_code))
print("")
formatted_code, _ = FormatCode(unformatted_code)
print("formatted code:")
print(repr(formatted_code))
print("")
diff, _ = FormatCode(unformatted_code, print_diff=True)
"""
This is empty but should be:
--- <unknown> (original)
+++ <unknown> (reformatted)
@@ -1 +1 @@
-f(a=1, b=2)
\ No newline at end of file
+f(a=1, b=2)
"""
print("diff:")
print(diff)
print("")