From b565924894c4ec35ab4584ef3a23c35087116b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edouard=20Choini=C3=A8re?= <27212526+echoix@users.noreply.github.com> Date: Sun, 14 Jul 2024 05:59:20 -0400 Subject: [PATCH] style: repeated-global (FURB154) (#4048) --- gui/wxpython/gcp/manager.py | 22 +++++------------ gui/wxpython/image2target/ii2t_manager.py | 22 +++++------------ gui/wxpython/location_wizard/wizard.py | 18 ++------------ gui/wxpython/photo2image/ip2i_manager.py | 12 +++------ pyproject.toml | 3 +-- python/grass/script/vector.py | 3 +-- python/grass/temporal/core.py | 30 +++++++---------------- 7 files changed, 28 insertions(+), 82 deletions(-) diff --git a/gui/wxpython/gcp/manager.py b/gui/wxpython/gcp/manager.py index 692de174f55..ed55bd7c553 100644 --- a/gui/wxpython/gcp/manager.py +++ b/gui/wxpython/gcp/manager.py @@ -73,9 +73,7 @@ # # global variables # -global src_map -global tgt_map -global maptype +global maptype, src_map, tgt_map src_map = "" tgt_map = {"raster": "", "vector": ""} @@ -138,9 +136,7 @@ def __init__(self, parent, giface): # mapset for xy map to georectify self.newmapset = "" - global maptype - global src_map - global tgt_map + global maptype, src_map, tgt_map # src_map = '' # tgt_map = '' @@ -875,8 +871,7 @@ def __init__(self, wizard, parent): def OnSrcSelection(self, event): """Source map to display selected""" - global src_map - global maptype + global maptype, src_map src_map = self.srcselection.GetValue() @@ -912,8 +907,7 @@ def OnTgtVectSelection(self, event): tgt_map["vector"] = self.tgtvectselection.GetValue() def OnPageChanging(self, event=None): - global src_map - global tgt_map + global src_map, tgt_map if event.GetDirection() and (src_map == ""): GMessage( @@ -925,9 +919,7 @@ def OnPageChanging(self, event=None): self.parent.SwitchEnv("target") def OnEnterPage(self, event=None): - global maptype - global src_map - global tgt_map + global maptype, src_map, tgt_map self.srcselection.SetElementList(maptype) @@ -3369,9 +3361,7 @@ def OnExtension(self, event): self.parent.extension = self.ext_txt.GetValue() def UpdateSettings(self): - global src_map - global tgt_map - global maptype + global maptype, src_map, tgt_map layers = None diff --git a/gui/wxpython/image2target/ii2t_manager.py b/gui/wxpython/image2target/ii2t_manager.py index 19a66f01dba..39e77d9a7e4 100644 --- a/gui/wxpython/image2target/ii2t_manager.py +++ b/gui/wxpython/image2target/ii2t_manager.py @@ -79,9 +79,7 @@ # # global variables # -global src_map -global tgt_map -global maptype +global src_map, tgt_map, maptype src_map = "" tgt_map = {"raster": "", "vector": ""} @@ -178,9 +176,7 @@ def __init__(self, parent, giface): # mapset for xy map to georectify self.newmapset = "" - global maptype - global src_map - global tgt_map + global maptype, src_map, tgt_map # src_map = '' # tgt_map = '' @@ -879,8 +875,7 @@ def __init__(self, wizard, parent): def OnSrcSelection(self, event): """Source map to display selected""" - global src_map - global maptype + global src_map, maptype src_map = self.srcselection.GetValue() @@ -916,8 +911,7 @@ def OnTgtVectSelection(self, event): tgt_map["vector"] = self.tgtvectselection.GetValue() def OnPageChanging(self, event=None): - global src_map - global tgt_map + global src_map, tgt_map if event.GetDirection() and (src_map == ""): GMessage( @@ -929,9 +923,7 @@ def OnPageChanging(self, event=None): self.parent.SwitchEnv("target") def OnEnterPage(self, event=None): - global maptype - global src_map - global tgt_map + global maptype, src_map, tgt_map self.srcselection.SetElementList(maptype) @@ -3318,9 +3310,7 @@ def OnExtension(self, event): self.parent.extension = self.ext_txt.GetValue() def UpdateSettings(self): - global src_map - global tgt_map - global maptype + global src_map, tgt_map, maptype layers = None diff --git a/gui/wxpython/location_wizard/wizard.py b/gui/wxpython/location_wizard/wizard.py index 41c84d4ca70..670710a6ebf 100644 --- a/gui/wxpython/location_wizard/wizard.py +++ b/gui/wxpython/location_wizard/wizard.py @@ -75,14 +75,7 @@ from grass.script import core as grass from grass.exceptions import OpenError -global coordsys -global north -global south -global east -global west -global resolution -global wizerror -global translist +global coordsys, north, south, east, west, resolution, wizerror, translist if globalvar.CheckWxVersion(version=[4, 1, 0]): search_cancel_evt = wx.EVT_SEARCH_CANCEL @@ -2539,14 +2532,7 @@ def __init__(self, parent, grassdatabase): self.__cleanUp() def __cleanUp(self): - global coordsys - global north - global south - global east - global west - global resolution - global wizerror - global translist + global coordsys, north, south, east, west, resolution, wizerror, translist coordsys = None north = None diff --git a/gui/wxpython/photo2image/ip2i_manager.py b/gui/wxpython/photo2image/ip2i_manager.py index c3b87ac3928..c8a4eb85105 100644 --- a/gui/wxpython/photo2image/ip2i_manager.py +++ b/gui/wxpython/photo2image/ip2i_manager.py @@ -59,9 +59,7 @@ # # global variables # -global src_map -global tgt_map -global maptype +global src_map, tgt_map, maptype src_map = "" tgt_map = "" @@ -95,9 +93,7 @@ class GCPWizard: def __init__( self, parent, giface, group, raster, raster1, camera, order, extension ): - global maptype - global src_map - global tgt_map + global maptype, src_map, tgt_map maptype = "raster" rendertype = "raster" self.parent = parent # GMFrame @@ -2406,9 +2402,7 @@ def OnExtension(self, event): self.parent.extension = self.ext_txt.GetValue() def UpdateSettings(self): - global src_map - global tgt_map - global maptype + global src_map, tgt_map, maptype layers = None diff --git a/pyproject.toml b/pyproject.toml index 7d544473f60..64b7c033708 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -153,7 +153,6 @@ ignore = [ "FBT003", # boolean-positional-value-in-call "FURB118", # reimplemented-operator "FURB152", # math-constant - "FURB154", # repeated-global "I001", # unsorted-imports "ISC003", # explicit-string-concatenation "PERF203", # try-except-in-loop @@ -389,7 +388,7 @@ ignore = [ "python/grass/temporal/univar_statistics.py" = ["INT002"] "raster3d/r3.flow/testsuite/r3flow_test.py" = ["FLY002"] "raster3d/r3.gradient/testsuite/r3gradient_test.py" = ["FLY002"] -"scripts/d.polar/d.polar.py" = ["INT002"] +"scripts/d.polar/d.polar.py" = ["FURB154", "INT002"] "scripts/g.extension.all/g.extension.all.py" = ["INT002"] "scripts/g.extension/g.extension.py" = ["INT002"] "scripts/i.oif/i.oif.py" = ["INT003"] diff --git a/python/grass/script/vector.py b/python/grass/script/vector.py index 4a57b5db07b..ca3caf18471 100644 --- a/python/grass/script/vector.py +++ b/python/grass/script/vector.py @@ -430,8 +430,7 @@ def vector_what( return data # lazy import - global json - global orderedDict + global json, orderedDict if json is None: import json if orderedDict is None: diff --git a/python/grass/temporal/core.py b/python/grass/temporal/core.py index 9ae898cb536..12dafeb4fd5 100644 --- a/python/grass/temporal/core.py +++ b/python/grass/temporal/core.py @@ -454,8 +454,7 @@ def stop_subprocesses(): """Stop the messenger and C-interface subprocesses that are started by tgis.init() """ - global message_interface - global c_library_interface + global message_interface, c_library_interface if message_interface: message_interface.stop() if c_library_interface: @@ -473,8 +472,7 @@ def get_available_temporal_mapsets(): :returns: A dictionary, mapset names are keys, the tuple (driver, database) are the values """ - global c_library_interface - global message_interface + global c_library_interface, message_interface mapsets = c_library_interface.available_mapsets() @@ -562,17 +560,11 @@ def init(raise_fatal_error=False, skip_db_version_check=False): """ # We need to set the correct database backend and several global variables # from the GRASS mapset specific environment variables of g.gisenv and t.connect - global tgis_backend - global tgis_database - global tgis_database_string - global tgis_dbmi_paramstyle - global tgis_db_version - global raise_on_error - global enable_mapset_check - global enable_timestamp_write - global current_mapset - global current_location - global current_gisdbase + global tgis_backend, tgis_database, tgis_database_string # noqa: FURB154 + global tgis_dbmi_paramstyle, tgis_db_version # noqa: FURB154 + global raise_on_error # noqa: FURB154 + global enable_mapset_check, enable_timestamp_write # noqa: FURB154 + global current_mapset, current_location, current_gisdbase # noqa: FURB154 raise_on_error = raise_fatal_error @@ -846,10 +838,7 @@ def create_temporal_database(dbif): :param dbif: The database interface to be used """ - global tgis_backend - global tgis_version - global tgis_db_version - global tgis_database_string + global tgis_backend, tgis_version, tgis_db_version, tgis_database_string template_path = get_sql_template_path() msgr = get_tgis_message_interface() @@ -977,8 +966,7 @@ def upgrade_temporal_database(dbif): :param dbif: The database interface to be used """ - global tgis_database_string - global tgis_db_version + global tgis_database_string, tgis_db_version metadata = get_tgis_metadata(dbif)