33import copy
44import os
55import re
6- from typing import Dict , NamedTuple , List , Pattern
6+ from typing import Dict , NamedTuple , List , Set , Pattern
77from dataclasses import dataclass
88
99from fortls .constants import (
5656)
5757USE_info = NamedTuple (
5858 "USE_info" ,
59- [("mod_name" , str ), ("only_list" , List [str ]), ("rename_map" , Dict [str , str ])],
59+ [("mod_name" , str ), ("only_list" , Set [str ]), ("rename_map" , Dict [str , str ])],
6060)
6161GEN_info = NamedTuple (
6262 "GEN_info" ,
@@ -79,9 +79,9 @@ def get_use_tree(
7979 scope : fortran_scope ,
8080 use_dict : dict ,
8181 obj_tree : dict ,
82- only_list : list = [] ,
83- rename_map : dict = {} ,
84- curr_path : list = [] ,
82+ only_list : list = None ,
83+ rename_map : dict = None ,
84+ curr_path : list = None ,
8585):
8686 def intersect_only (use_stmnt ):
8787 tmp_list = []
@@ -97,6 +97,13 @@ def intersect_only(use_stmnt):
9797 tmp_map .pop (val1 , None )
9898 return tmp_list , tmp_map
9999
100+ if only_list is None :
101+ only_list = []
102+ if rename_map is None :
103+ rename_map = {}
104+ if curr_path is None :
105+ curr_path = []
106+
100107 # Detect and break circular references
101108 if scope .FQSN in curr_path :
102109 return use_dict
@@ -297,15 +304,17 @@ def __init__(
297304 self ,
298305 mod_name : str ,
299306 line_number : int ,
300- only_list : list = [] ,
301- rename_map : dict = {} ,
307+ only_list : list = None ,
308+ rename_map : dict = None ,
302309 ):
303310 self .mod_name : str = mod_name .lower ()
304311 self .line_number : int = line_number
305- self .only_list : list = [only .lower () for only in only_list ]
306- self .rename_map : dict = {
307- key .lower (): value .lower () for key , value in rename_map .items ()
308- }
312+ if only_list is not None :
313+ self .only_list : list = [only .lower () for only in only_list ]
314+ if rename_map is not None :
315+ self .rename_map : dict = {
316+ key .lower (): value .lower () for key , value in rename_map .items ()
317+ }
309318
310319
311320class fortran_diagnostic :
@@ -466,15 +475,19 @@ def req_named_end(self):
466475 def check_valid_parent (self ):
467476 return True
468477
469- def check_definition (self , obj_tree , known_types = {}, interface = False ):
478+ def check_definition (self , obj_tree , known_types : dict = None , interface = False ):
479+ if known_types is None :
480+ known_types = {}
470481 return None , known_types
471482
472483
473484class fortran_scope (fortran_obj ):
474485 def __init__ (self , file_ast , line_number : int , name : str ):
475486 self .base_setup (file_ast , line_number , name )
476487
477- def base_setup (self , file_ast , sline : int , name : str , keywords : list = []):
488+ def base_setup (self , file_ast , sline : int , name : str , keywords : list = None ):
489+ if keywords is None :
490+ keywords = []
478491 self .file_ast : fortran_ast = file_ast
479492 self .sline : int = sline
480493 self .eline : int = sline
@@ -514,7 +527,13 @@ def copy_from(self, copy_source):
514527 self .implicit_vars = copy_source .implicit_vars
515528 self .implicit_line = copy_source .implicit_line
516529
517- def add_use (self , use_mod , line_number , only_list = [], rename_map = {}):
530+ def add_use (
531+ self , use_mod , line_number , only_list : list = None , rename_map : dict = None
532+ ):
533+ if only_list is None :
534+ only_list = []
535+ if rename_map is None :
536+ rename_map = {}
518537 self .use .append (USE_line (use_mod , line_number , only_list , rename_map ))
519538
520539 def set_inherit (self , inherit_type ):
@@ -841,8 +860,10 @@ def __init__(
841860 name : str ,
842861 args : str = "" ,
843862 mod_flag : bool = False ,
844- keywords : list = [] ,
863+ keywords : list = None ,
845864 ):
865+ if keywords is None :
866+ keywords = []
846867 self .base_setup (file_ast , line_number , name , keywords = keywords )
847868 self .args : str = args .replace (" " , "" )
848869 self .args_snip : str = self .args
@@ -1055,10 +1076,12 @@ def __init__(
10551076 name : str ,
10561077 args : str = "" ,
10571078 mod_flag : bool = False ,
1058- keywords : list = [] ,
1079+ keywords : list = None ,
10591080 return_type = None ,
10601081 result_var = None ,
10611082 ):
1083+ if keywords is None :
1084+ keywords = []
10621085 self .base_setup (file_ast , line_number , name , keywords = keywords )
10631086 self .args : str = args .replace (" " , "" ).lower ()
10641087 self .args_snip : str = self .args
@@ -1495,7 +1518,7 @@ class fortran_int(fortran_scope):
14951518 def __init__ (
14961519 self ,
14971520 file_ast : fortran_ast ,
1498- line_number : list ,
1521+ line_number : int ,
14991522 name : str ,
15001523 abstract : bool = False ,
15011524 ):
@@ -1540,9 +1563,11 @@ def __init__(
15401563 name : str ,
15411564 var_desc : str ,
15421565 keywords : list ,
1543- keyword_info : dict = {} ,
1566+ keyword_info : dict = None ,
15441567 link_obj = None ,
15451568 ):
1569+ if keyword_info is None :
1570+ keyword_info = {}
15461571 self .base_setup (
15471572 file_ast , line_number , name , var_desc , keywords , keyword_info , link_obj
15481573 )
@@ -1920,7 +1945,7 @@ def get_enc_scope_name(self):
19201945 def add_scope (
19211946 self ,
19221947 new_scope : fortran_scope ,
1923- END_SCOPE_REGEX ,
1948+ END_SCOPE_REGEX : Pattern [ str ] ,
19241949 exportable : bool = True ,
19251950 req_container : bool = False ,
19261951 ):
0 commit comments