From cd64472259769315a343a6ac2e8dc0ffc6a7f1df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edouard=20Choini=C3=A8re?= <27212526+echoix@users.noreply.github.com> Date: Mon, 8 Jul 2024 11:39:55 -0400 Subject: [PATCH] style: Fix pylint pointless-statement (W0104) (#3996) * temporal: Actually call dbif.close() to fix pylint pointless-statement (W0104) * g.extension: Fix pylint pointless-statement (W0104) * temporal: Fix pointless-statement (W0104) in temporal_granularity * temporal: Fix pointless-statement (W0104) in c_libraries_interface.py, _read_vector_history() function * i.atcorr: Remove useless and non-working print statements in create_iwave.py * python(grass.imaging): Use PIL.__version__ call to fix pylint pointless-statement * style: Ignore ruff useless-expression (B018) for a gunittest data file. Equivalent to pylint pointless-statement / W010 * style: Enable ruff useless-expression (B018) (equivalent to pylint pointless-statement / W010) --- imagery/i.atcorr/create_iwave.py | 8 -------- pyproject.toml | 2 +- python/grass/imaging/images2gif.py | 2 +- python/grass/temporal/abstract_map_dataset.py | 12 ++++++------ python/grass/temporal/c_libraries_interface.py | 2 +- python/grass/temporal/temporal_granularity.py | 1 - scripts/g.extension/g.extension.py | 3 +-- 7 files changed, 10 insertions(+), 20 deletions(-) diff --git a/imagery/i.atcorr/create_iwave.py b/imagery/i.atcorr/create_iwave.py index c304ab71645..5fc1fa78559 100644 --- a/imagery/i.atcorr/create_iwave.py +++ b/imagery/i.atcorr/create_iwave.py @@ -35,18 +35,15 @@ def usage(): """How to use this...""" print("create_iwave.py ") - print print("Generates filter function template for iwave.cpp from csv file. Note:") print("- csv file must have wl response for each band in each column") print("- first line must be a header with wl followed by band names") print("- all following lines will be the data.") print("If spectral response is null, leave field empty in csv file. Example:") - print print("WL(nm),band 1,band 2,band 3,band 4") print("455,0.93,,,") print("485,0.94,0.00,,") print("545,0.00,0.87,0.00,") - print print("This script will interpolate the filter functions to 2.5 nm steps") print("and output a cpp template file in the IWave format to be added to iwave.cpp") @@ -207,7 +204,6 @@ def write_cpp(bands, values, sensor, folder): # keep in sync with IWave::parse() rthresh = 0.01 - print print(" > Response peaks from interpolation to 2.5 nm steps:") # getting necessary data @@ -334,7 +330,6 @@ def main(): # getting sensor name from full csv file name sensor = os.path.splitext(os.path.basename(inputfile))[0] - print print(" > Getting sensor name from csv file: %s" % (sensor)) # getting data from file @@ -344,7 +339,6 @@ def main(): # consider only wavelengths with a reasonably large response # around the peak response, keep in sync with IWave::parse() rthresh = 0.01 - print print(" > Response peaks from input file:") for b in range(1, len(bands) + 1): lowl = 0 @@ -372,7 +366,6 @@ def main(): # writing file in same folder of input file write_cpp(bands, values, sensor, os.path.dirname(inputfile)) - print print( " > Filter functions exported to %s" % ("sensors_csv/" + sensor + "_cpp_template.txt") @@ -385,7 +378,6 @@ def main(): " > Don't forget to add the necessary data to the files" " iwave.h, geomcond.h, geomcond.cpp, and to i.atcorr.html" ) - print if __name__ == "__main__": diff --git a/pyproject.toml b/pyproject.toml index a86c28d5eb0..83e3560f874 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -94,7 +94,6 @@ ignore = [ "B008", # function-call-in-default-argument "B009", # get-attr-with-constant "B015", # useless-comparison - "B018", # useless-expression "B020", # loop-variable-overrides-iterator "B023", # function-uses-loop-variable "B026", # star-arg-unpacking-after-keyword-arg @@ -388,6 +387,7 @@ ignore = [ "python/grass/__init__.py" = ["PYI056"] "python/grass/gunittest/loader.py" = ["PYI024"] "python/grass/gunittest/multireport.py" = ["PYI024"] +"python/grass/gunittest/testsu*/d*/s*/s*/subsub*/t*/test_segfaut.py" = ["B018"] "python/grass/gunittest/testsuite/test_assertions_rast3d.py" = ["FLY002"] "python/grass/jupyter/tests/reprojection_renderer_test.py" = ["PT013"] "python/grass/jupyter/testsuite/interactivemap_test.py" = ["PGH004"] diff --git a/python/grass/imaging/images2gif.py b/python/grass/imaging/images2gif.py index 95d72add09a..b80f452cf8c 100644 --- a/python/grass/imaging/images2gif.py +++ b/python/grass/imaging/images2gif.py @@ -72,7 +72,7 @@ pillow = True try: - PIL.__version__ # test if user has Pillow or PIL + PIL_version = PIL.__version__ # test if user has Pillow or PIL except AttributeError: pillow = False from PIL.GifImagePlugin import getheader, getdata diff --git a/python/grass/temporal/abstract_map_dataset.py b/python/grass/temporal/abstract_map_dataset.py index 89956189651..576ac347d7e 100644 --- a/python/grass/temporal/abstract_map_dataset.py +++ b/python/grass/temporal/abstract_map_dataset.py @@ -1132,7 +1132,7 @@ def get_registered_stds(self, dbif=None, mapset=None): datasets = None if connection_state_changed: - dbif.close + dbif.close() return datasets @@ -1168,7 +1168,7 @@ def add_stds_to_register(self, stds_id, dbif=None, execute=True): # Check if the dataset is already present if stds_id in datasets: if connection_state_changed: - dbif.close + dbif.close() return "" datasets.append(stds_id) @@ -1183,7 +1183,7 @@ def add_stds_to_register(self, stds_id, dbif=None, execute=True): statement = self.stds_register.get_update_statement_mogrified(dbif=dbif) if connection_state_changed: - dbif.close + dbif.close() return statement @@ -1210,13 +1210,13 @@ def remove_stds_from_register(self, stds_id, dbif=None, execute=True): # Check if no datasets are present if datasets is None: if connection_state_changed: - dbif.close + dbif.close() return "" # Check if the dataset is already present if stds_id not in datasets: if connection_state_changed: - dbif.close + dbif.close() return "" datasets.remove(stds_id) @@ -1231,7 +1231,7 @@ def remove_stds_from_register(self, stds_id, dbif=None, execute=True): statement = self.stds_register.get_update_statement_mogrified(dbif=dbif) if connection_state_changed: - dbif.close + dbif.close() return statement diff --git a/python/grass/temporal/c_libraries_interface.py b/python/grass/temporal/c_libraries_interface.py index bd934c83b21..8ee5b1a2ad4 100644 --- a/python/grass/temporal/c_libraries_interface.py +++ b/python/grass/temporal/c_libraries_interface.py @@ -1110,7 +1110,7 @@ def _read_vector_history(name, mapset): kvp["creation_time"] = decode(libvector.Vect_get_map_date(byref(Map))) kvp["creator"] = decode(libvector.Vect_get_person(byref(Map))) else: - None + kvp = None libvector.Vect_close(byref(Map)) return kvp diff --git a/python/grass/temporal/temporal_granularity.py b/python/grass/temporal/temporal_granularity.py index ffe84646e5b..c23dd701c5c 100644 --- a/python/grass/temporal/temporal_granularity.py +++ b/python/grass/temporal/temporal_granularity.py @@ -83,7 +83,6 @@ def check_granularity_string(granularity, temporal_type): False """ - temporal_type if granularity is None: return False diff --git a/scripts/g.extension/g.extension.py b/scripts/g.extension/g.extension.py index 3f2f5b6c7ee..0e7d9296b57 100644 --- a/scripts/g.extension/g.extension.py +++ b/scripts/g.extension/g.extension.py @@ -2600,8 +2600,7 @@ def resolve_known_host_service(url, name, branch): url = "{prefix}{base}{suffix}".format( prefix=actual_start, base=url.rstrip("/"), suffix=suffix ) - gs.verbose - (_("Will use the following URL for download: {0}").format(url)) + gs.verbose(_("Will use the following URL for download: {0}").format(url)) return "remote_zip", url else: return None, None