Skip to content

Commit

Permalink
grass.temporal: Add typing annotations for boolean parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
echoix committed Nov 3, 2024
1 parent cffabc8 commit 49ef577
Show file tree
Hide file tree
Showing 25 changed files with 165 additions and 122 deletions.
6 changes: 3 additions & 3 deletions python/grass/temporal/abstract_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def is_in_db(self, dbif=None, mapset=None):
def delete(self):
"""Delete dataset from database if it exists"""

def insert(self, dbif=None, execute=True):
def insert(self, dbif=None, execute: bool = True):
"""Insert dataset into database
:param dbif: The database interface to be used
Expand Down Expand Up @@ -434,7 +434,7 @@ def insert(self, dbif=None, execute=True):
dbif.close()
return statement

def update(self, dbif=None, execute=True, ident=None):
def update(self, dbif=None, execute: bool = True, ident=None):
"""Update the dataset entry in the database from the internal structure
excluding None variables
Expand Down Expand Up @@ -468,7 +468,7 @@ def update(self, dbif=None, execute=True, ident=None):
dbif.close()
return statement

def update_all(self, dbif=None, execute=True, ident=None):
def update_all(self, dbif=None, execute: bool = True, ident=None):
"""Update the dataset entry in the database from the internal structure
and include None variables.
Expand Down
20 changes: 10 additions & 10 deletions python/grass/temporal/abstract_map_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def print_shell_info(self) -> None:
if self.is_topology_build():
self.print_topology_shell_info()

def insert(self, dbif=None, execute=True):
def insert(self, dbif=None, execute: bool = True):
"""Insert the map content into the database from the internal
structure
Expand All @@ -364,7 +364,7 @@ def insert(self, dbif=None, execute=True):
self.write_timestamp_to_grass()
return AbstractDataset.insert(self, dbif=dbif, execute=execute)

def update(self, dbif=None, execute=True):
def update(self, dbif=None, execute: bool = True):
"""Update the map content in the database from the internal structure
excluding None variables
Expand All @@ -383,7 +383,7 @@ def update(self, dbif=None, execute=True):
self.write_timestamp_to_grass()
return AbstractDataset.update(self, dbif, execute)

def update_all(self, dbif=None, execute=True):
def update_all(self, dbif=None, execute: bool = True):
"""Update the map content in the database from the internal structure
including None variables
Expand Down Expand Up @@ -721,7 +721,7 @@ def set_temporal_extent(self, extent) -> None:

self.set_absolute_time(start, end)

def temporal_buffer(self, increment, update=False, dbif=None) -> None:
def temporal_buffer(self, increment, update: bool = False, dbif=None) -> None:
"""Create a temporal buffer based on an increment
For absolute time the increment must be a string of type "integer
Expand Down Expand Up @@ -870,7 +870,7 @@ def set_spatial_extent(self, spatial_extent) -> None:
"""
self.spatial_extent.set_spatial_extent(spatial_extent)

def spatial_buffer(self, size, update=False, dbif=None) -> None:
def spatial_buffer(self, size, update: bool = False, dbif=None) -> None:
"""Buffer the spatial extent by a given size in all
spatial directions.
Expand Down Expand Up @@ -902,7 +902,7 @@ def spatial_buffer(self, size, update=False, dbif=None) -> None:
if update:
self.spatial_extent.update(dbif)

def spatial_buffer_2d(self, size, update=False, dbif=None) -> None:
def spatial_buffer_2d(self, size, update: bool = False, dbif=None) -> None:
"""Buffer the spatial extent by a given size in 2d
spatial directions.
Expand Down Expand Up @@ -972,7 +972,7 @@ def check_for_correct_time(self):

return True

def delete(self, dbif=None, update=True, execute=True):
def delete(self, dbif=None, update: bool = True, execute: bool = True):
"""Delete a map entry from database if it exists
Remove dependent entries:
Expand Down Expand Up @@ -1034,7 +1034,7 @@ def delete(self, dbif=None, update=True, execute=True):

return statement

def unregister(self, dbif=None, update=True, execute=True):
def unregister(self, dbif=None, update: bool = True, execute: bool = True):
"""Remove the map entry in each space time dataset in which this map
is registered
Expand Down Expand Up @@ -1125,7 +1125,7 @@ def get_registered_stds(self, dbif=None, mapset=None):

# this fn should not be in a class for maps,
# but instead in a class for stds: AbstractSpaceTimeDataset ?
def add_stds_to_register(self, stds_id, dbif=None, execute=True):
def add_stds_to_register(self, stds_id, dbif=None, execute: bool = True):
"""Add a new space time dataset to the register
:param stds_id: The id of the space time dataset to be registered
Expand Down Expand Up @@ -1174,7 +1174,7 @@ def add_stds_to_register(self, stds_id, dbif=None, execute=True):

return statement

def remove_stds_from_register(self, stds_id, dbif=None, execute=True):
def remove_stds_from_register(self, stds_id, dbif=None, execute: bool = True):
"""Remove a space time dataset from the register
:param stds_id: The id of the space time dataset to removed from
Expand Down
14 changes: 8 additions & 6 deletions python/grass/temporal/abstract_space_time_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, ident) -> None:
# SpaceTimeRasterDataset related only
self.semantic_label = None

def get_name(self, semantic_label=True):
def get_name(self, semantic_label: bool = True):
"""Get dataset name including semantic label filter if enabled.
:param bool semantic_label: True to return dataset name
Expand Down Expand Up @@ -363,7 +363,7 @@ def set_relative_time_unit(self, unit) -> None:
self.msgr.fatal(_("Unsupported temporal unit: %s") % (unit))
self.relative_time.set_unit(unit)

def insert(self, dbif=None, execute=True):
def insert(self, dbif=None, execute: bool = True):
"""Insert the space time dataset content into the database from the internal
structure
Expand Down Expand Up @@ -615,7 +615,7 @@ def check_temporal_topology(self, maps=None, dbif=None):

return True

def sample_by_dataset(self, stds, method=None, spatial=False, dbif=None):
def sample_by_dataset(self, stds, method=None, spatial: bool = False, dbif=None):
"""Sample this space time dataset with the temporal topology
of a second space time dataset
Expand Down Expand Up @@ -822,7 +822,9 @@ def sample_by_dataset(self, stds, method=None, spatial=False, dbif=None):

return obj_list

def sample_by_dataset_sql(self, stds, method=None, spatial=False, dbif=None):
def sample_by_dataset_sql(
self, stds, method=None, spatial: bool = False, dbif=None
):
"""Sample this space time dataset with the temporal topology
of a second space time dataset using SQL queries.
Expand Down Expand Up @@ -2358,7 +2360,7 @@ def rename(self, ident, dbif=None) -> None:
if connection_state_changed:
dbif.close()

def delete(self, dbif=None, execute=True):
def delete(self, dbif=None, execute: bool = True):
"""Delete a space time dataset from the temporal database
This method removes the space time dataset from the temporal
Expand Down Expand Up @@ -2666,7 +2668,7 @@ def register_map(self, map, dbif=None):

return True

def unregister_map(self, map, dbif=None, execute=True):
def unregister_map(self, map, dbif=None, execute: bool = True):
"""Unregister a map from the space time dataset.
This method takes care of the un-registration of a map
Expand Down
2 changes: 1 addition & 1 deletion python/grass/temporal/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def aggregate_by_topology(
nprocs=1,
spatial=None,
dbif=None,
overwrite=False,
overwrite: bool = False,
file_limit=1000,
):
"""Aggregate a list of raster input maps with r.series
Expand Down
6 changes: 3 additions & 3 deletions python/grass/temporal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def get_enable_timestamp_write():
message_interface = None


def _init_tgis_message_interface(raise_on_error=False) -> None:
def _init_tgis_message_interface(raise_on_error: bool = False) -> None:
"""Initiate the global message interface
:param raise_on_error: If True raise a FatalError exception in case of
Expand Down Expand Up @@ -302,7 +302,7 @@ def get_tgis_c_library_interface():
raise_on_error = False


def set_raise_on_error(raise_exp=True):
def set_raise_on_error(raise_exp: bool = True):
"""Define behavior on fatal error, invoked using the tgis messenger
interface (msgr.fatal())
Expand Down Expand Up @@ -512,7 +512,7 @@ def get_available_temporal_mapsets():
###############################################################################


def init(raise_fatal_error=False, skip_db_version_check=False):
def init(raise_fatal_error: bool = False, skip_db_version_check: bool = False):
"""This function set the correct database backend from GRASS environmental
variables and creates the grass temporal database structure for raster,
vector and raster3d maps as well as for the space-time datasets strds,
Expand Down
4 changes: 2 additions & 2 deletions python/grass/temporal/datetime_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ def compute_datetime_delta(start, end):
###############################################################################


def check_datetime_string(time_string, use_dateutil=True):
def check_datetime_string(time_string, use_dateutil: bool = True):
"""Check if a string can be converted into a datetime object and return the object
In case datutil is not installed the supported ISO string formats are:
Expand Down Expand Up @@ -966,7 +966,7 @@ def create_suffix_from_datetime(start_time, granularity):
return start_time.strftime(suffix_units[granularity.split(" ")[1]])


def create_time_suffix(mapp, end=False):
def create_time_suffix(mapp, end: bool = False):
"""Create a datetime string based on a map datetime object
:param mapp: a temporal map dataset
Expand Down
2 changes: 1 addition & 1 deletion python/grass/temporal/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def extract_dataset(
base,
time_suffix,
nprocs=1,
register_null=False,
register_null: bool = False,
layer=1,
vtype="point,line,boundary,centroid,area,face",
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion python/grass/temporal/gui_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
###############################################################################


def tlist_grouped(type, group_type=False, dbif=None):
def tlist_grouped(type, group_type: bool = False, dbif=None):
"""List of temporal elements grouped by mapsets.
Returns a dictionary where the keys are mapset
Expand Down
4 changes: 2 additions & 2 deletions python/grass/temporal/list_stds.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class NoAliasIndentListSafeDumper(yaml.SafeDumper):
def ignore_aliases(self, data):
return True

def increase_indent(self, flow=False, indentless=False):
def increase_indent(self, flow: bool = False, indentless: bool = False):
return super().increase_indent(flow=flow, indentless=False)

dict_rows = []
Expand Down Expand Up @@ -481,7 +481,7 @@ def list_maps_of_stds(
where,
separator,
method,
no_header=False,
no_header: bool = False,
gran=None,
dbif=None,
outpath=None,
Expand Down
4 changes: 2 additions & 2 deletions python/grass/temporal/mapcalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def dataset_mapcalculator(
base,
method,
nprocs=1,
register_null=False,
spatial=False,
register_null: bool = False,
spatial: bool = False,
):
"""Perform map-calculations of maps from different space time
raster/raster3d datasets, using a specific sampling method
Expand Down
20 changes: 10 additions & 10 deletions python/grass/temporal/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def print_shell_info(self) -> None:
"""Print information about this class in shell style"""
self._print_info_body(shell=True)

def _print_info_head(self, shell=False) -> None:
def _print_info_head(self, shell: bool = False) -> None:
"""Print information about this class (head part).
No header printed in shell style mode.
Expand All @@ -262,7 +262,7 @@ def _print_info_head(self, shell=False) -> None:
" +-------------------- Metadata information ----------------------------------+" # noqa: E501
)

def _print_info_body(self, shell=False) -> None:
def _print_info_body(self, shell: bool = False) -> None:
"""Print information about this class (body part).
:param bool shell: True for human readable style otherwise shell style
Expand Down Expand Up @@ -660,7 +660,7 @@ class VectorMetadata(SQLDatabaseInterface):
def __init__(
self,
ident=None,
is_3d=False,
is_3d: bool = False,
number_of_points=None,
number_of_lines=None,
number_of_boundaries=None,
Expand Down Expand Up @@ -1023,7 +1023,7 @@ def print_shell_info(self) -> None:
self._print_info_body(shell=True)
self._print_info_tail(shell=True)

def _print_info_head(self, shell=False) -> None:
def _print_info_head(self, shell: bool = False) -> None:
"""Print information about this class (head part).
No header printed in shell style mode.
Expand All @@ -1035,13 +1035,13 @@ def _print_info_head(self, shell=False) -> None:
" +-------------------- Metadata information ----------------------------------+" # noqa: E501
)

def _print_info_body(self, shell=False) -> None:
def _print_info_body(self, shell: bool = False) -> None:
"""Print information about this class (body part).
:param bool shell: True for human readable style otherwise shell style
"""

def _print_info_tail(self, shell=False) -> None:
def _print_info_tail(self, shell: bool = False) -> None:
"""Print information about this class (tail part).
:param bool shell: True for human readable style otherwise shell style
Expand Down Expand Up @@ -1273,7 +1273,7 @@ def get_ewres_max(self):
max_max = property(fget=get_max_max)
aggregation_type = property(fset=set_aggregation_type, fget=get_aggregation_type)

def _print_info_body(self, shell=False) -> None:
def _print_info_body(self, shell: bool = False) -> None:
"""Print information about this class (body part).
:param bool shell: True for human readable style otherwise shell style
Expand Down Expand Up @@ -1460,7 +1460,7 @@ def print_shell_info(self) -> None:
self._print_info_head(shell=True)
super().print_shell_info()

def _print_info_body(self, shell=False) -> None:
def _print_info_body(self, shell: bool = False) -> None:
"""Print information about this class (body part).
:param bool shell: True for human readable style otherwise shell style
Expand Down Expand Up @@ -1615,7 +1615,7 @@ def print_shell_info(self) -> None:
self._print_info_head(shell=True)
super().print_shell_info()

def _print_info_body(self, shell=False) -> None:
def _print_info_body(self, shell: bool = False) -> None:
"""Print information about this class (body part).
:param bool shell: True for human readable style otherwise shell style
Expand Down Expand Up @@ -1879,7 +1879,7 @@ def print_shell_info(self) -> None:
self._print_info_head(shell=True)
super().print_shell_info()

def _print_info_body(self, shell=False) -> None:
def _print_info_body(self, shell: bool = False) -> None:
"""Print information about this class (body part).
:param bool shell: True for human readable style otherwise shell style
Expand Down
Loading

0 comments on commit 49ef577

Please sign in to comment.