Skip to content

Commit 577172d

Browse files
committed
Simplify if-conditionals
Some ast file objects return NoneType so keeping is not None is required. Break process file into small program units and ad types.
1 parent 7d9ed0d commit 577172d

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

fortls/parse_fortran.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ def parser_debug_msg(msg: str, line: str, ln: int):
14251425
select_counter = 0
14261426
block_id_stack = []
14271427
semi_split = []
1428-
doc_string = None
1428+
doc_string: str = None
14291429
if file_obj.fixed:
14301430
COMMENT_LINE_MATCH = FIXED_COMMENT_LINE_MATCH
14311431
DOC_COMMENT_MATCH = FIXED_DOC_MATCH
@@ -1448,15 +1448,15 @@ def parser_debug_msg(msg: str, line: str, ln: int):
14481448
continue # Skip empty lines
14491449
# Skip comment lines
14501450
match = COMMENT_LINE_MATCH.match(line)
1451-
if match is not None:
1451+
if match:
14521452
# Check for documentation
14531453
doc_match = DOC_COMMENT_MATCH.match(line)
1454-
if doc_match is not None:
1454+
if doc_match:
14551455
doc_lines = [line[doc_match.end(0) :].strip()]
14561456
if doc_match.group(1) == ">":
14571457
doc_forward = True
14581458
else:
1459-
if (doc_string is not None) and (doc_string != ""):
1459+
if doc_string:
14601460
doc_lines = [doc_string] + doc_lines
14611461
doc_string = None
14621462
doc_forward = False
@@ -1482,7 +1482,7 @@ def parser_debug_msg(msg: str, line: str, ln: int):
14821482
)
14831483
continue
14841484
# Handle trailing doc strings
1485-
if (doc_string is not None) and (doc_string != ""):
1485+
if doc_string:
14861486
file_ast.add_doc("!! " + doc_string)
14871487
log.debug(f"{doc_string} !!! Doc string({line_number})")
14881488
doc_string = None
@@ -1539,7 +1539,7 @@ def parser_debug_msg(msg: str, line: str, ln: int):
15391539
if file_ast.END_SCOPE_REGEX is not None:
15401540
match = END_WORD_REGEX.match(line_no_comment)
15411541
# Handle end statement
1542-
if match is not None:
1542+
if match:
15431543
end_scope_word = None
15441544
if match.group(1) is None:
15451545
end_scope_word = ""
@@ -1580,11 +1580,11 @@ def parser_debug_msg(msg: str, line: str, ln: int):
15801580
continue
15811581
# Skip if known generic code line
15821582
match = NON_DEF_REGEX.match(line_no_comment)
1583-
if match is not None:
1583+
if match:
15841584
continue
15851585
# Mark implicit statement
15861586
match = IMPLICIT_REGEX.match(line_no_comment)
1587-
if match is not None:
1587+
if match:
15881588
err_message = None
15891589
if file_ast.current_scope is None:
15901590
err_message = "IMPLICIT statement without enclosing scope"
@@ -1593,7 +1593,7 @@ def parser_debug_msg(msg: str, line: str, ln: int):
15931593
file_ast.current_scope.set_implicit(False, line_number)
15941594
else:
15951595
file_ast.current_scope.set_implicit(True, line_number)
1596-
if err_message is not None:
1596+
if err_message:
15971597
file_ast.parse_errors.append(
15981598
{
15991599
"line": line_number,
@@ -1607,7 +1607,7 @@ def parser_debug_msg(msg: str, line: str, ln: int):
16071607
continue
16081608
# Mark contains statement
16091609
match = CONTAINS_REGEX.match(line_no_comment)
1610-
if match is not None:
1610+
if match:
16111611
err_message = None
16121612
try:
16131613
if file_ast.current_scope is None:
@@ -1616,7 +1616,7 @@ def parser_debug_msg(msg: str, line: str, ln: int):
16161616
file_ast.current_scope.mark_contains(line_number)
16171617
except ValueError:
16181618
err_message = "Multiple CONTAINS statements in scope"
1619-
if err_message is not None:
1619+
if err_message:
16201620
file_ast.parse_errors.append(
16211621
{
16221622
"line": line_number,
@@ -1629,9 +1629,9 @@ def parser_debug_msg(msg: str, line: str, ln: int):
16291629
parser_debug_msg("CONTAINS", line, line_number)
16301630
continue
16311631
# Look for trailing doc string
1632-
if line_post_comment is not None:
1632+
if line_post_comment:
16331633
doc_match = FREE_DOC_MATCH.match(line_post_comment)
1634-
if doc_match is not None:
1634+
if doc_match:
16351635
doc_string = line_post_comment[doc_match.end(0) :].strip()
16361636
# Loop through tests
16371637
obj_read = None

0 commit comments

Comments
 (0)