Skip to content

Commit a29a059

Browse files
committed
Ugly fix for #153
This is a sort of brute-force workaround to avoid #153. Likely not up to the standard of `fprettify` but 'works-for-me'. Test amended to cover the corner case, I think.
1 parent b5df13b commit a29a059

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

fprettify/__init__.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,8 @@ def replace_relational_single_fline(f_line, cstyle):
14161416
.ne. <--> /=
14171417
"""
14181418

1419+
# keep track of whether the line may be affected
1420+
line_affected = False
14191421
new_line = f_line
14201422

14211423
# only act on lines that do contain a relation
@@ -1459,8 +1461,25 @@ def replace_relational_single_fline(f_line, cstyle):
14591461
line_parts[pos] = part
14601462

14611463
new_line = "".join(line_parts)
1464+
line_affected = True
14621465

1463-
return new_line
1466+
return new_line, line_affected
1467+
1468+
1469+
def replace_relational_lines(lines, cstyle):
1470+
"""
1471+
format a list of lines - replaces scalar relational
1472+
operators in logical expressions to either Fortran or C-style
1473+
by calling original function for single line.
1474+
"""
1475+
1476+
new_lines = []
1477+
1478+
for f_line in lines:
1479+
new_line, changed = replace_relational_single_fline(f_line, cstyle)
1480+
new_lines.append(new_line)
1481+
1482+
return new_lines
14641483

14651484

14661485
def replace_keywords_single_fline(f_line, case_dict):
@@ -2241,7 +2260,10 @@ def reformat_ffile_combined(
22412260
f_line = f_line.strip(" ")
22422261

22432262
if impose_replacements:
2244-
f_line = replace_relational_single_fline(f_line, cstyle)
2263+
f_line, relation_found = replace_relational_single_fline(f_line, cstyle)
2264+
if relation_found:
2265+
updated_lines = replace_relational_lines(lines, cstyle)
2266+
linebreak_pos = get_linebreak_pos(updated_lines, filter_fypp=not indent_fypp)
22452267

22462268
if impose_case:
22472269
f_line = replace_keywords_single_fline(f_line, case_dict)

0 commit comments

Comments
 (0)