yapf
yapf copied to clipboard
incorrect format with assert according to pep8
If there is a long statement having assert statement then, yapf is changing into format which is not consistent with pep8 guidelines.
sample.py
def someConditionTrue():
return True
class Foo():
def bar(self, longVar2):
longVar1 = 2
for _ in range(5):
if not True:
assert someConditionTrue(), "The condition if not true will print this {} and {}".format(longVar1, longVar2)
Command being run:
yapf --style='{based_on_style: pep8, indent_width: 2}' sample.py
Output begin generated:
def someConditionTrue():
return True
class Foo():
def bar(self, longVar2):
longVar1 = 2
for _ in range(5):
if not True:
assert someConditionTrue(
), "The condition if not true will print this {} and {}".format(
longVar1, longVar2)
Expected Output:
def someConditionTrue():
return True
class Foo():
def bar(self, longVar2):
longVar1 = 2
for _ in range(5):
if not True:
assert someConditionTrue(), \
"The condition if not true will print this {} and {}".format(
longVar1, longVar2)
We at YAPF refuse to add or remove tokens from the program. It just leads to bugs and headaches and, worse, could change the semantics of the program.
I modified file to
def someConditionTrue():
return True
class Foo():
def bar(self, longVar2):
longVar1 = 2
for _ in range(5):
if not True:
assert someConditionTrue(), \
"The condition if not true will print this {} and {}".format(longVar1, longVar2)
I ran it with:
yapf --style='{based_on_style: pep8, indent_width: 2, column_limit: 79}' sample.py
Output being generated:
def someConditionTrue():
return True
class Foo():
def bar(self, longVar2):
longVar1 = 2
for _ in range(5):
if not True:
assert someConditionTrue(), \
"The condition if not true will print this {} and {}".format(longVar1, longVar2)
The last line is not being formatted correctly. Correct me if I am wrong, but I believe, longVar1 should start from next line. Also, shouldn't double quotes start directly below someConditionTrue().