diff --git a/pyproject.toml b/pyproject.toml index 0dbc7549763..83561606a07 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -721,7 +721,6 @@ disable = [ "RP0401", # Report: Imports checker: External dependencies "RP0801", # Report: Similarities: Duplication "W0101", # Unreachable code (unreachable) - "W0102", # Dangerous default value %s as argument (dangerous-default-value) "W0104", # Statement seems to have no effect (pointless-statement) "W0106", # Expression "%s" is assigned to nothing (expression-not-assigned) "W0108", # Lambda may not be necessary (unnecessary-lambda) @@ -745,7 +744,6 @@ disable = [ "W0611", # (unused-import) "W0612", # Unused variable %r (unused-variable) "W0613", # Unused argument %r (unused-argument) - "W0614", # Unused import(s) %s from wildcard import of %s (unused-wildcard-import) "W0621", # Redefining name %r from outer scope (line %s) (redefined-outer-name) "W0621", # Redefining name %r from outer scope (line %s) (redefined-outer-name) "W0622", # Redefining built-in %r (redefined-builtin) diff --git a/python/grass/pygrass/messages/__init__.py b/python/grass/pygrass/messages/__init__.py index 5735398dafc..461848f6454 100644 --- a/python/grass/pygrass/messages/__init__.py +++ b/python/grass/pygrass/messages/__init__.py @@ -339,10 +339,10 @@ def test_fatal_error(self, message: str) -> None: time.sleep(1) +_MSGR_INSTANCE: Messenger | None = None + + def get_msgr( - instance=[ - None, - ], *args, **kwargs, ) -> Messenger: @@ -358,9 +358,10 @@ def get_msgr( >>> msgr0 is msgr2 False """ - if not instance[0]: - instance[0] = Messenger(*args, **kwargs) - return instance[0] + global _MSGR_INSTANCE + if _MSGR_INSTANCE is None: + _MSGR_INSTANCE = Messenger(*args, **kwargs) + return _MSGR_INSTANCE if __name__ == "__main__": diff --git a/python/grass/temporal/temporal_algebra.py b/python/grass/temporal/temporal_algebra.py index 37da1099bc9..d6eb1ce91b2 100644 --- a/python/grass/temporal/temporal_algebra.py +++ b/python/grass/temporal/temporal_algebra.py @@ -1112,19 +1112,22 @@ def overlay_map_extent( returncode = 0 return returncode - def set_temporal_extent_list(self, maplist, topolist=["EQUAL"], temporal="l"): + def set_temporal_extent_list(self, maplist, topolist=None, temporal="l"): """Change temporal extent of map list based on temporal relations to other map list and given temporal operator. :param maplist: List of map objects for which relations has been build correctly. - :param topolist: List of strings of temporal relations. + :param topolist: List of strings of temporal relations. If None, + defaults to ["EQUAL"] internally. :param temporal: The temporal operator specifying the temporal extent operation (intersection, union, disjoint union, right reference, left reference). :return: Map list with specified temporal extent. """ + if topolist is None: + topolist = ["EQUAL"] resultdict = {} temporal_topo_list, spatial_topo_list = self._check_topology(topolist=topolist) @@ -1399,7 +1402,7 @@ def build_spatio_temporal_topology_list( self, maplistA, maplistB=None, - topolist=["EQUAL"], + topolist=None, assign_val: bool = False, count_map: bool = False, compare_bool: bool = False, @@ -1411,7 +1414,8 @@ def build_spatio_temporal_topology_list( :param maplistA: List of maps. :param maplistB: List of maps. - :param topolist: List of strings of spatio-temporal relations. + :param topolist: List of strings of spatio-temporal relations. If None, + defaults to ["EQUAL"] internally. :param assign_val: Boolean for assigning a boolean map value based on the map_values from the compared map list by topological relationships. @@ -1573,6 +1577,8 @@ def build_spatio_temporal_topology_list( """ # Check the topology definitions and return the list of temporal and spatial # topological relations that must be fulfilled + if topolist is None: + topolist = ["EQUAL"] temporal_topo_list, spatial_topo_list = self._check_topology(topolist=topolist) resultdict = {} @@ -1624,20 +1630,25 @@ def build_spatio_temporal_topology_list( return sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime) def assign_bool_value( - self, map_i, temporal_topo_list=["EQUAL"], spatial_topo_list=[] + self, map_i, temporal_topo_list=None, spatial_topo_list=None ) -> bool: """Function to assign boolean map value based on the map_values from the compared map list by topological relationships. :param map_i: Map object with temporal extent. - :param temporal_topo_list: List of strings for given temporal relations. - :param spatial_topo_list: List of strings for given spatial relations. + :param temporal_topo_list: List of strings for given temporal relations. If None, + defaults to ["EQUAL"] internally. + :param spatial_topo_list: List of strings for given spatial relations. If None, + defaults to empty list internally. :return: Map object with conditional value that has been assigned by relation maps that fulfil the topological relationships to maplistB specified in temporal_topo_list. """ - + if temporal_topo_list is None: + temporal_topo_list = ["EQUAL"] + if spatial_topo_list is None: + spatial_topo_list = [] temporal_relations = map_i.get_temporal_relations() condition_value_list = [] for topo in temporal_topo_list: @@ -1669,8 +1680,8 @@ def compare_bool_value( map_i, compop, aggregate, - temporal_topo_list=["EQUAL"], - spatial_topo_list=[], + temporal_topo_list=None, + spatial_topo_list=None, ): """Function to evaluate two map lists with boolean values by boolean comparison operator. @@ -1678,13 +1689,18 @@ def compare_bool_value( :param map_i: Map object with temporal extent. :param compop: Comparison operator, && or ||. :param aggregate: Aggregation operator for relation map list, & or \\|. - :param temporal_topo_list: List of strings for given temporal relations. - :param spatial_topo_list: List of strings for given spatial relations. + :param temporal_topo_list: List of strings for given temporal relations. If None, + defaults to ["EQUAL"] internally. + :param spatial_topo_list: List of strings for given spatial relations. If None, + defaults to empty list internally. :return: Map object with conditional value that has been evaluated by comparison operators. """ - + if temporal_topo_list is None: + temporal_topo_list = ["EQUAL"] + if spatial_topo_list is None: + spatial_topo_list = [] temporal_relations = map_i.get_temporal_relations() # Build conditional list with elements from related maps and given relation @@ -1760,7 +1776,7 @@ def perform_temporal_selection( self, maplistA, maplistB, - topolist=["EQUAL"], + topolist=None, inverse: bool = False, assign_val: bool = False, ): @@ -1770,7 +1786,8 @@ def perform_temporal_selection( expression. :param maplistB: List of maps representing the right side of a temporal expression. - :param topolist: List of strings of temporal relations. + :param topolist: List of strings of temporal relations. If None, + defaults to ["EQUAL"] internally. :param inverse: Boolean value that specifies if the selection should be inverted. :param assign_val: Boolean for assigning a boolean map value based on @@ -1828,6 +1845,8 @@ def perform_temporal_selection( Map a4 has no equal relation to mapset mapsB """ + if topolist is None: + topolist = ["EQUAL"] if not inverse: topolist = self.build_spatio_temporal_topology_list( maplistA, maplistB, topolist, assign_val=assign_val @@ -1849,14 +1868,15 @@ def perform_temporal_selection( # Sort list of maps chronological. return sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime) - def set_granularity(self, maplistA, maplistB, toperator="l", topolist=["EQUAL"]): + def set_granularity(self, maplistA, maplistB, toperator="l", topolist=None): """This function sets the temporal extends of a list of maps based on another map list. :param maplistB: List of maps. :param maplistB: List of maps. :param toperator: String containing the temporal operator: l, r, d, i, u. - :param topolist: List of topological relations. + :param topolist: List of topological relations. If None, defaults to ["EQUAL"] + internally. :return: List of maps with the new temporal extends. @@ -1900,6 +1920,8 @@ def set_granularity(self, maplistA, maplistB, toperator="l", topolist=["EQUAL"]) :raises SyntaxError: If an unpermitted temporal relation name is used in ``topolist`` """ + if topolist is None: + topolist = ["EQUAL"] topologylist = [ "EQUAL", "FOLLOWS", @@ -2153,7 +2175,7 @@ def eval_global_var(self, gvar, maplist): map_i.condition_value = boolname return maplist - def eval_map_list(self, maplist, thenlist, topolist=["EQUAL"]): + def eval_map_list(self, maplist, thenlist, topolist=None): """This function transfers boolean values from temporal expression from one map list to another by their topology. These boolean values are added to the maps as condition_value. @@ -2161,6 +2183,8 @@ def eval_map_list(self, maplist, thenlist, topolist=["EQUAL"]): :param maplist: List of map objects containing boolean map values. :param thenlist: List of map objects where the boolean values should be added. + :param topolist: List of temporal relations between the two map lists. If None, + defaults to ["EQUAL"] internally. :return: List of maps from thenlist with added conditional boolean values. """ @@ -2172,11 +2196,13 @@ def eval_map_list(self, maplist, thenlist, topolist=["EQUAL"]): # inverse = True, # topolist = topolist) # Combining the selection and inverse selection list. + if topolist is None: + topolist = ["EQUAL"] return self.perform_temporal_selection( thenlist, maplist, assign_val=True, topolist=topolist ) - def build_condition_list(self, tvarexpr, thenlist, topolist=["EQUAL"]): + def build_condition_list(self, tvarexpr, thenlist, topolist=None): """This function evaluates temporal variable expressions of a conditional expression in two steps. At first it combines stepwise the single conditions by their relations with @@ -2207,7 +2233,8 @@ def build_condition_list(self, tvarexpr, thenlist, topolist=["EQUAL"]): :return: Map list with conditional values for all temporal expressions. """ - + if topolist is None: + topolist = ["EQUAL"] # Evaluate the temporal variable expression and compute the temporal combination # of conditions. diff --git a/python/grass/temporal/temporal_raster_base_algebra.py b/python/grass/temporal/temporal_raster_base_algebra.py index 308edc948c6..06c8301be86 100644 --- a/python/grass/temporal/temporal_raster_base_algebra.py +++ b/python/grass/temporal/temporal_raster_base_algebra.py @@ -204,7 +204,7 @@ def build_spatio_temporal_topology_list( self, maplistA, maplistB=None, - topolist=["EQUAL"], + topolist=None, assign_val: bool = False, count_map: bool = False, compare_bool: bool = False, @@ -220,7 +220,7 @@ def build_spatio_temporal_topology_list( :param maplistA: List of maps. :param maplistB: List of maps. - :param topolist: List of strings of temporal relations. + :param topolist: List of strings of temporal relations. If None, defaults to ["EQUAL"] internally. :param assign_val: Boolean for assigning a boolean map value based on the map_values from the compared map list by topological relationships. @@ -275,6 +275,8 @@ def build_spatio_temporal_topology_list( a9@B """ + if topolist is None: + topolist = ["EQUAL"] if self.debug: print( topolist, @@ -418,8 +420,8 @@ def compare_cmd_value( map_i, compop, aggregate, - temporal_topo_list=["EQUAL"], - spatial_topo_list=[], + temporal_topo_list=None, + spatial_topo_list=None, convert: bool = False, ): """Function to evaluate two map lists with boolean values by boolean @@ -437,8 +439,10 @@ def compare_cmd_value( :param map_i: Map object with temporal extent. :param compop: Comparison operator, && or ||. :param aggregate: Aggregation operator for relation map list, & or \\|. - :param temporal_topo_list: List of strings for given temporal relations. - :param spatial_topo_list: List of strings for given spatial relations. + :param temporal_topo_list: List of strings for given temporal relations. If None, + defaults to ["EQUAL"] internally. + :param spatial_topo_list: List of strings for given spatial relations. If None, + defaults to empty list internally. :param convert: Boolean if conditional values should be converted to r.mapcalc command strings. @@ -447,6 +451,10 @@ def compare_cmd_value( """ # Build command list list with elements from related maps and given relation # operator. + if temporal_topo_list is None: + temporal_topo_list = ["EQUAL"] + if spatial_topo_list is None: + spatial_topo_list = [] if convert and "condition_value" in dir(map_i): if map_i.condition_value != []: cmdstring = str(int(map_i.condition_value[0])) @@ -500,7 +508,7 @@ def compare_cmd_value( return cmd_value_str def operator_cmd_value( - self, map_i, operator, temporal_topo_list=["EQUAL"], spatial_topo_list=[] + self, map_i, operator, temporal_topo_list=None, spatial_topo_list=None ): """Function to evaluate two map lists by given arithmetic operator. @@ -512,7 +520,10 @@ def operator_cmd_value( :return: Map object with command list with operators that has been evaluated by implicit aggregation. """ - + if temporal_topo_list is None: + temporal_topo_list = ["EQUAL"] + if spatial_topo_list is None: + spatial_topo_list = [] temporal_relations = map_i.get_temporal_relations() # Build comandlist list with elements from related maps and given relation @@ -553,7 +564,7 @@ def operator_cmd_value( def set_temporal_extent_list( self, maplist, - topolist=["EQUAL"], + topolist=None, temporal="l", cmd_bool: bool = False, cmd_type=None, @@ -564,7 +575,8 @@ def set_temporal_extent_list( :param maplist: List of map objects for which relations has been build correctly. - :param topolist: List of strings of temporal relations. + :param topolist: List of strings of temporal relations. If None, + defaults to ["EQUAL"] internally. :param temporal: The temporal operator specifying the temporal extent operation (intersection, union, disjoint union, right reference, left reference). @@ -575,6 +587,8 @@ def set_temporal_extent_list( :return: Map list with specified temporal extent and optional command string. """ + if topolist is None: + topolist = ["EQUAL"] resultdict = {} temporal_topo_list, spatial_topo_list = self._check_topology(topolist=topolist) @@ -643,8 +657,8 @@ def build_condition_cmd_list( iflist, thenlist, elselist=None, - condition_topolist=["EQUAL"], - conclusion_topolist=["EQUAL"], + condition_topolist=None, + conclusion_topolist=None, temporal="l", null: bool = False, ): @@ -657,9 +671,9 @@ def build_condition_cmd_list( :param elselist: Map list with temporal extents and command list or numeric string. :param condition_topolist: List of strings for given temporal relations between - conditions and conclusions. + conditions and conclusions. If None, defaults to ["EQUAL"] internally. :param conclusion_topolist: List of strings for given temporal relations between - conditions (then and else). + conditions (then and else). If None, defaults to ["EQUAL"] internally. :param temporal: The temporal operator specifying the temporal extent operation (intersection, union, disjoint union, right reference, left reference). @@ -667,6 +681,10 @@ def build_condition_cmd_list( :return: map list with resulting command string for given condition type. """ + if condition_topolist is None: + condition_topolist = ["EQUAL"] + if conclusion_topolist is None: + conclusion_topolist = ["EQUAL"] resultlist = [] # First merge conclusion command maplists or strings. # Check if alternative conclusion map list is given. diff --git a/python/grass/temporal/temporal_vector_algebra.py b/python/grass/temporal/temporal_vector_algebra.py index 95ad181b817..64c09c24dec 100644 --- a/python/grass/temporal/temporal_vector_algebra.py +++ b/python/grass/temporal/temporal_vector_algebra.py @@ -186,7 +186,7 @@ def build_spatio_temporal_topology_list( self, maplistA, maplistB=None, - topolist=["EQUAL"], + topolist=None, assign_val: bool = False, count_map: bool = False, compare_bool: bool = False, @@ -202,7 +202,7 @@ def build_spatio_temporal_topology_list( :param maplistA: List of maps. :param maplistB: List of maps. - :param topolist: List of strings of temporal relations. + :param topolist: List of strings of temporal relations. If None, defaults to ["EQUAL"] internally. :param assign_val: Boolean for assigning a boolean map value based on the map_values from the compared map list by topological relationships. @@ -223,6 +223,8 @@ def build_spatio_temporal_topology_list( :return: List of maps from maplistA that fulfil the topological relationships to maplistB specified in topolist. """ + if topolist is None: + topolist = ["EQUAL"] topologylist = [ "EQUAL", "FOLLOWS", @@ -285,12 +287,13 @@ def build_spatio_temporal_topology_list( # Sort list of maps chronological. return sorted(resultlist, key=AbstractDatasetComparisonKeyStartTime) - def overlay_cmd_value(self, map_i, tbrelations, function, topolist=["EQUAL"]): + def overlay_cmd_value(self, map_i, tbrelations, function, topolist=None): """Function to evaluate two map lists by given overlay operator. :param map_i: Map object with temporal extent. :param tbrelations: List of temporal relation to map_i. - :param topolist: List of strings for given temporal relations. + :param topolist: List of strings for given temporal relations. If None, + defaults to ["EQUAL"] internally. :param function: Overlay operator, &|+^~. :return: Map object with command list with operators that has been @@ -298,6 +301,8 @@ def overlay_cmd_value(self, map_i, tbrelations, function, topolist=["EQUAL"]): """ # Build comandlist list with elements from related maps and given relation # operator. + if topolist is None: + topolist = ["EQUAL"] resultlist = [] # Define overlay operation dictionary. overlaydict = {"&": "and", "|": "or", "^": "xor", "~": "not", "+": "disor"} @@ -345,19 +350,21 @@ def overlay_cmd_value(self, map_i, tbrelations, function, topolist=["EQUAL"]): return resultlist - def set_temporal_extent_list(self, maplist, topolist=["EQUAL"], temporal="l"): + def set_temporal_extent_list(self, maplist, topolist=None, temporal="l"): """Change temporal extent of map list based on temporal relations to other map list and given temporal operator. :param maplist: List of map objects for which relations has been build correctly. - :param topolist: List of strings of temporal relations. + :param topolist: List of strings of temporal relations. If None, defaults to ["EQUAL"] internally. :param temporal: The temporal operator specifying the temporal extent operation (intersection, union, disjoint union, right reference, left reference). :return: Map list with specified temporal extent. """ + if topolist is None: + topolist = ["EQUAL"] resultdict = {} for map_i in maplist: