From 480e050b206f6239f9a6f67fd9d176f1c83e3ff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edouard=20Choini=C3=A8re?= <27212526+echoix@users.noreply.github.com> Date: Mon, 30 Sep 2024 18:50:15 -0400 Subject: [PATCH 1/7] style: Fix redundant-open-modes (UP015) (#4410) --- display/d.mon/render_cmd.py | 2 +- gui/wxpython/core/gconsole.py | 2 +- gui/wxpython/core/render.py | 2 +- gui/wxpython/core/settings.py | 4 ++-- gui/wxpython/core/watchdog.py | 2 +- gui/wxpython/core/workspace.py | 2 +- gui/wxpython/gcp/manager.py | 4 ++-- gui/wxpython/gmodeler/model.py | 2 +- gui/wxpython/gui_core/forms.py | 2 +- gui/wxpython/gui_core/ghelp.py | 4 ++-- gui/wxpython/gui_core/widgets.py | 2 +- gui/wxpython/image2target/ii2t_gis_set.py | 2 +- gui/wxpython/image2target/ii2t_manager.py | 4 ++-- gui/wxpython/location_wizard/wizard.py | 12 +++++------- gui/wxpython/mapdisp/main.py | 4 ++-- gui/wxpython/modules/colorrules.py | 2 +- gui/wxpython/modules/mcalc_builder.py | 2 +- gui/wxpython/photo2image/ip2i_manager.py | 8 ++++---- gui/wxpython/psmap/instructions.py | 2 +- gui/wxpython/vnet/vnet_data.py | 2 +- imagery/i.atcorr/create_iwave.py | 2 +- lib/init/grass.py | 8 ++++---- man/build_html.py | 4 ++-- man/build_rest.py | 4 ++-- pyproject.toml | 1 - python/grass/grassdb/history.py | 6 ++---- python/grass/gunittest/checkers.py | 2 +- python/grass/gunittest/reporters.py | 2 +- python/grass/jupyter/interactivemap.py | 2 +- python/grass/pygrass/gis/__init__.py | 2 +- python/grass/pygrass/modules/grid/grid.py | 2 +- python/grass/pygrass/modules/interface/env.py | 2 +- python/grass/pygrass/raster/category.py | 2 +- python/grass/pygrass/tests/set_mapset.py | 2 +- python/grass/script/core.py | 4 ++-- python/grass/script/utils.py | 4 ++-- python/grass/temporal/register.py | 2 +- python/grass/temporal/stds_import.py | 4 ++-- raster/r.contour/testsuite/test_r_contour.py | 4 ++-- raster/r.in.gdal/testsuite/test_r_in_gdal.py | 2 +- raster/r.what/testsuite/test_r_what.py | 2 +- scripts/d.correlate/d.correlate.py | 4 ++-- scripts/d.frame/d.frame.py | 2 +- scripts/db.univar/db.univar.py | 2 +- scripts/g.extension.all/g.extension.all.py | 2 +- scripts/g.search.modules/g.search.modules.py | 6 +++--- scripts/r.in.wms/wms_gdal_drv.py | 2 +- scripts/r.pack/r.pack.py | 2 +- scripts/v.unpack/v.unpack.py | 2 +- temporal/t.rast.what/t.rast.what.py | 6 +++--- temporal/t.remove/t.remove.py | 2 +- temporal/t.unregister/t.unregister.py | 2 +- 52 files changed, 78 insertions(+), 83 deletions(-) diff --git a/display/d.mon/render_cmd.py b/display/d.mon/render_cmd.py index 7678a1442e4..cf153c0b017 100644 --- a/display/d.mon/render_cmd.py +++ b/display/d.mon/render_cmd.py @@ -39,7 +39,7 @@ def remove_mapfile(mapfile): # read environment variables from file def read_env_file(env_file): width = height = legfile = None - fd = open(env_file, "r") + fd = open(env_file) if fd is None: grass.fatal("Unable to open file '{0}'".format(env_file)) lines = fd.readlines() diff --git a/gui/wxpython/core/gconsole.py b/gui/wxpython/core/gconsole.py index 7575c401c98..092f9bc704a 100644 --- a/gui/wxpython/core/gconsole.py +++ b/gui/wxpython/core/gconsole.py @@ -678,7 +678,7 @@ def load_source(modname, filename): skipInterface = True if os.path.splitext(command[0])[1] in {".py", ".sh"}: try: - with open(command[0], "r") as sfile: + with open(command[0]) as sfile: for line in sfile: if len(line) < 3: continue diff --git a/gui/wxpython/core/render.py b/gui/wxpython/core/render.py index 5b3e3096043..1d4ed6f5386 100644 --- a/gui/wxpython/core/render.py +++ b/gui/wxpython/core/render.py @@ -896,7 +896,7 @@ def GetWindow(self): env["GISDBASE"], env["LOCATION_NAME"], env["MAPSET"], "WIND" ) try: - windfile = open(filename, "r") + windfile = open(filename) except OSError as e: sys.exit( _("Error: Unable to open '%(file)s'. Reason: %(ret)s. wxGUI exited.\n") diff --git a/gui/wxpython/core/settings.py b/gui/wxpython/core/settings.py index 2b2d3b28526..ef3a3031cee 100644 --- a/gui/wxpython/core/settings.py +++ b/gui/wxpython/core/settings.py @@ -922,7 +922,7 @@ def update_nested_dict_by_dict(dictionary, update): return dictionary try: - with open(self.filePath, "r") as f: + with open(self.filePath) as f: update = json.load(f, object_hook=settings_JSON_decode_hook) update_nested_dict_by_dict(settings, update) except json.JSONDecodeError as e: @@ -942,7 +942,7 @@ def _readLegacyFile(self, settings=None): settings = self.userSettings try: - fd = open(self.legacyFilePath, "r") + fd = open(self.legacyFilePath) except OSError: sys.stderr.write( _("Unable to read settings file <%s>\n") % self.legacyFilePath diff --git a/gui/wxpython/core/watchdog.py b/gui/wxpython/core/watchdog.py index 591bb36b477..76302aeea0a 100644 --- a/gui/wxpython/core/watchdog.py +++ b/gui/wxpython/core/watchdog.py @@ -68,7 +68,7 @@ def on_modified(self, event): self.modified_time = timestamp # wait to make sure file writing is done time.sleep(0.1) - with open(event.src_path, "r") as f: + with open(event.src_path) as f: gisrc = {} for line in f: key, val = line.split(":") diff --git a/gui/wxpython/core/workspace.py b/gui/wxpython/core/workspace.py index 9550aa73488..be4eb1fda37 100644 --- a/gui/wxpython/core/workspace.py +++ b/gui/wxpython/core/workspace.py @@ -1742,7 +1742,7 @@ def read(self, parent): :return: list of map layers """ try: - file = open(self.filename, "r") + file = open(self.filename) except OSError: wx.MessageBox( parent=parent, diff --git a/gui/wxpython/gcp/manager.py b/gui/wxpython/gcp/manager.py index a96555fe271..528d710f72c 100644 --- a/gui/wxpython/gcp/manager.py +++ b/gui/wxpython/gcp/manager.py @@ -119,7 +119,7 @@ def __init__(self, parent, giface): self.target_gisrc = os.environ["GISRC"] self.gisrc_dict = {} try: - f = open(self.target_gisrc, "r") + f = open(self.target_gisrc) for line in f: line = line.replace("\n", "").strip() if len(line) < 1: @@ -1603,7 +1603,7 @@ def ReadGCPs(self): GError(parent=self, message=_("target mapwin not defined")) try: - f = open(self.file["points"], "r") + f = open(self.file["points"]) GCPcnt = 0 for line in f: diff --git a/gui/wxpython/gmodeler/model.py b/gui/wxpython/gmodeler/model.py index 59ea791192c..98a7204abbe 100644 --- a/gui/wxpython/gmodeler/model.py +++ b/gui/wxpython/gmodeler/model.py @@ -546,7 +546,7 @@ def _substituteFile(self, item, params=None, checkOnly=False): for finput in self.fileInput: # read lines - fd = open(finput, "r") + fd = open(finput) try: data = self.fileInput[finput] = fd.read() finally: diff --git a/gui/wxpython/gui_core/forms.py b/gui/wxpython/gui_core/forms.py index 74bcc00f85a..1ef623feaf7 100644 --- a/gui/wxpython/gui_core/forms.py +++ b/gui/wxpython/gui_core/forms.py @@ -2588,7 +2588,7 @@ def OnFileLoad(self, event): data = "" try: - f = open(path, "r") + f = open(path) except OSError as e: gcmd.GError( parent=self, diff --git a/gui/wxpython/gui_core/ghelp.py b/gui/wxpython/gui_core/ghelp.py index 72e2564b74d..6713dbcc0a3 100644 --- a/gui/wxpython/gui_core/ghelp.py +++ b/gui/wxpython/gui_core/ghelp.py @@ -274,7 +274,7 @@ def _pageCopyright(self): """Copyright information""" copyfile = os.path.join(os.getenv("GISBASE"), "COPYING") if os.path.exists(copyfile): - copyrightFile = open(copyfile, "r") + copyrightFile = open(copyfile) copytext = copyrightFile.read() copyrightFile.close() else: @@ -303,7 +303,7 @@ def _pageLicense(self): """Licence about""" licfile = os.path.join(os.getenv("GISBASE"), "GPL.TXT") if os.path.exists(licfile): - licenceFile = open(licfile, "r") + licenceFile = open(licfile) license = "".join(licenceFile.readlines()) licenceFile.close() else: diff --git a/gui/wxpython/gui_core/widgets.py b/gui/wxpython/gui_core/widgets.py index c959ebbbf50..5f2582f9b1e 100644 --- a/gui/wxpython/gui_core/widgets.py +++ b/gui/wxpython/gui_core/widgets.py @@ -1566,7 +1566,7 @@ def _loadSettings(self): return data try: - fd = open(self.settingsFile, "r") + fd = open(self.settingsFile) except OSError: return data diff --git a/gui/wxpython/image2target/ii2t_gis_set.py b/gui/wxpython/image2target/ii2t_gis_set.py index 187b01d1740..e63e39ba365 100644 --- a/gui/wxpython/image2target/ii2t_gis_set.py +++ b/gui/wxpython/image2target/ii2t_gis_set.py @@ -543,7 +543,7 @@ def _readGisRC(self): if gisrc and os.path.isfile(gisrc): try: - rc = open(gisrc, "r") + rc = open(gisrc) for line in rc: try: key, val = line.split(":", 1) diff --git a/gui/wxpython/image2target/ii2t_manager.py b/gui/wxpython/image2target/ii2t_manager.py index 1c9958c9cef..06693926ec3 100644 --- a/gui/wxpython/image2target/ii2t_manager.py +++ b/gui/wxpython/image2target/ii2t_manager.py @@ -159,7 +159,7 @@ def __init__(self, parent, giface): self.target_gisrc = os.environ["GISRC"] self.gisrc_dict = {} try: - f = open(self.target_gisrc, "r") + f = open(self.target_gisrc) for line in f: line = line.replace("\n", "").strip() if len(line) < 1: @@ -1627,7 +1627,7 @@ def ReadGCPs(self): GError(parent=self, message=_("target mapwin not defined")) try: - f = open(self.file["control_points"], "r") + f = open(self.file["control_points"]) GCPcnt = 0 for line in f: diff --git a/gui/wxpython/location_wizard/wizard.py b/gui/wxpython/location_wizard/wizard.py index 2cccdf5e301..28ce94fbc48 100644 --- a/gui/wxpython/location_wizard/wizard.py +++ b/gui/wxpython/location_wizard/wizard.py @@ -2543,7 +2543,7 @@ def __readData(self): """Get georeferencing information from tables in $GISBASE/etc/proj""" # read projection and parameters - f = open(os.path.join(globalvar.ETCDIR, "proj", "parms.table"), "r") + f = open(os.path.join(globalvar.ETCDIR, "proj", "parms.table")) self.projections = {} self.projdesc = {} for line in f: @@ -2566,7 +2566,7 @@ def __readData(self): f.close() # read datum definitions - f = open(os.path.join(globalvar.ETCDIR, "proj", "datum.table"), "r") + f = open(os.path.join(globalvar.ETCDIR, "proj", "datum.table")) self.datums = {} paramslist = [] for line in f: @@ -2584,7 +2584,7 @@ def __readData(self): f.close() # read Earth-based ellipsiod definitions - f = open(os.path.join(globalvar.ETCDIR, "proj", "ellipse.table"), "r") + f = open(os.path.join(globalvar.ETCDIR, "proj", "ellipse.table")) self.ellipsoids = {} for line in f: line = line.expandtabs(1) @@ -2600,9 +2600,7 @@ def __readData(self): f.close() # read Planetary ellipsiod definitions - f = open( - os.path.join(globalvar.ETCDIR, "proj", "ellipse.table.solar.system"), "r" - ) + f = open(os.path.join(globalvar.ETCDIR, "proj", "ellipse.table.solar.system")) self.planetary_ellipsoids = {} for line in f: line = line.expandtabs(1) @@ -2618,7 +2616,7 @@ def __readData(self): f.close() # read projection parameter description and parsing table - f = open(os.path.join(globalvar.ETCDIR, "proj", "desc.table"), "r") + f = open(os.path.join(globalvar.ETCDIR, "proj", "desc.table")) self.paramdesc = {} for line in f: line = line.strip() diff --git a/gui/wxpython/mapdisp/main.py b/gui/wxpython/mapdisp/main.py index 1e94d3d8ba2..016261d248d 100644 --- a/gui/wxpython/mapdisp/main.py +++ b/gui/wxpython/mapdisp/main.py @@ -108,7 +108,7 @@ def __init__(self, giface, cmdfile=None, mapfile=None): self.renderMgr = RenderMapMgr(self) # update legend file variable with the one d.mon uses - with open(monFile["env"], "r") as f: + with open(monFile["env"]) as f: lines = f.readlines() for line in lines: if "GRASS_LEGEND_FILE" in line: @@ -123,7 +123,7 @@ def GetLayersFromCmdFile(self): nlayers = 0 try: - fd = open(self.cmdfile, "r") + fd = open(self.cmdfile) lines = fd.readlines() fd.close() # detect d.out.file, delete the line from the cmd file and export diff --git a/gui/wxpython/modules/colorrules.py b/gui/wxpython/modules/colorrules.py index 5093cd7cf25..cad74f38c4b 100644 --- a/gui/wxpython/modules/colorrules.py +++ b/gui/wxpython/modules/colorrules.py @@ -700,7 +700,7 @@ def OnLoadRulesFile(self, event): self.rulesPanel.Clear() - fd = open(path, "r") + fd = open(path) self.ReadColorTable(ctable=fd.read()) fd.close() diff --git a/gui/wxpython/modules/mcalc_builder.py b/gui/wxpython/modules/mcalc_builder.py index e157375b4a4..b0f2f280409 100644 --- a/gui/wxpython/modules/mcalc_builder.py +++ b/gui/wxpython/modules/mcalc_builder.py @@ -759,7 +759,7 @@ def OnLoadExpression(self, event): return try: - fobj = open(path, "r") + fobj = open(path) mctxt = fobj.read() finally: fobj.close() diff --git a/gui/wxpython/photo2image/ip2i_manager.py b/gui/wxpython/photo2image/ip2i_manager.py index e27e763fb2a..5a2a1f14f21 100644 --- a/gui/wxpython/photo2image/ip2i_manager.py +++ b/gui/wxpython/photo2image/ip2i_manager.py @@ -118,7 +118,7 @@ def __init__( self.source_gisrc = os.environ["GISRC"] self.gisrc_dict = {} try: - f = open(self.target_gisrc, "r") + f = open(self.target_gisrc) for line in f: line = line.replace("\n", "").strip() if len(line) < 1: @@ -429,7 +429,7 @@ def __init__( import re try: - fc = open(self.file["camera"], mode="r") + fc = open(self.file["camera"]) fc_count = 0 for line in fc: fc_count += 1 @@ -438,7 +438,7 @@ def __init__( numberOfFiducial = int(line.split()[-1]) dataFiducialX = [] dataFiducialY = [] - fc = open(self.file["camera"], mode="r") + fc = open(self.file["camera"]) fc_count = 0 for line in fc: fc_count += 1 @@ -955,7 +955,7 @@ def ReadGCPs(self): GError(parent=self, message=_("target mapwin not defined")) try: - f = open(self.file["points"], "r") + f = open(self.file["points"]) GCPcnt = 0 for line in f: diff --git a/gui/wxpython/psmap/instructions.py b/gui/wxpython/psmap/instructions.py index 693e8024b57..3c1b2e6d7bb 100644 --- a/gui/wxpython/psmap/instructions.py +++ b/gui/wxpython/psmap/instructions.py @@ -1208,7 +1208,7 @@ def GetImageOrigSize(self, imagePath): # if eps, read info from header if os.path.splitext(fileName)[1].lower() == ".eps": bbInfo = "%%BoundingBox" - file = open(imagePath, "r") + file = open(imagePath) w = h = 0 while file: line = file.readline() diff --git a/gui/wxpython/vnet/vnet_data.py b/gui/wxpython/vnet/vnet_data.py index 6404fcac5c0..9c5b592e043 100644 --- a/gui/wxpython/vnet/vnet_data.py +++ b/gui/wxpython/vnet/vnet_data.py @@ -1070,7 +1070,7 @@ def GetLastModified(self): "head", ) try: - head = open(headPath, "r") + head = open(headPath) for line in head: i = line.find( "MAP DATE:", diff --git a/imagery/i.atcorr/create_iwave.py b/imagery/i.atcorr/create_iwave.py index 8afc6bebd36..a575d8089cd 100644 --- a/imagery/i.atcorr/create_iwave.py +++ b/imagery/i.atcorr/create_iwave.py @@ -59,7 +59,7 @@ def read_input(csvfile): first column is wavelength values are those of the discrete band filter functions """ - infile = open(csvfile, "r") + infile = open(csvfile) # get number of bands and band names bands = infile.readline().split(",") diff --git a/lib/init/grass.py b/lib/init/grass.py index 25486d9426c..233bcf53460 100755 --- a/lib/init/grass.py +++ b/lib/init/grass.py @@ -496,7 +496,7 @@ def create_gisrc(tmpdir, gisrcrc): def read_gisrc(filename): kv = {} try: - f = open(filename, "r") + f = open(filename) except OSError: return kv @@ -522,7 +522,7 @@ def write_gisrcrc(gisrcrc, gisrc, skip_variable=None): """Reads gisrc file and write to gisrcrc""" debug("Reading %s" % gisrc) number = 0 - with open(gisrc, "r") as f: + with open(gisrc) as f: lines = f.readlines() for line in lines: if skip_variable in line: @@ -535,7 +535,7 @@ def write_gisrcrc(gisrcrc, gisrc, skip_variable=None): def read_env_file(path): kv = {} - f = open(path, "r") + f = open(path) for line in f: k, v = line.split(":", 1) kv[k.strip()] = v.strip() @@ -1098,7 +1098,7 @@ def set_language(grass_config_dir): # Override value is stored in wxGUI preferences file. try: - with open(os.path.join(grass_config_dir, "wx.json"), "r") as json_file: + with open(os.path.join(grass_config_dir, "wx.json")) as json_file: try: language = json.load(json_file)["language"]["locale"]["lc_all"] except KeyError: diff --git a/man/build_html.py b/man/build_html.py index daa38b557f4..c89df29e290 100644 --- a/man/build_html.py +++ b/man/build_html.py @@ -393,7 +393,7 @@ def check_for_desc_override(basename): def read_file(name): - f = open(name, "r") + f = open(name) s = f.read() f.close() return s @@ -476,7 +476,7 @@ def write_html_footer(f, index_url, year=None): def get_desc(cmd): - f = open(cmd, "r") + f = open(cmd) while True: line = f.readline() if not line: diff --git a/man/build_rest.py b/man/build_rest.py index ea1dd7692d2..473827fcc86 100644 --- a/man/build_rest.py +++ b/man/build_rest.py @@ -271,7 +271,7 @@ def check_for_desc_override(basename): def read_file(name): - f = open(name, "r") + f = open(name) s = f.read() f.close() return s @@ -337,7 +337,7 @@ def write_rest_footer(f, index_url): def get_desc(cmd): - f = open(cmd, "r") + f = open(cmd) while True: line = f.readline() if not line: diff --git a/pyproject.toml b/pyproject.toml index 9e430071afc..c6cfac4185b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -258,7 +258,6 @@ ignore = [ "TRY201", # verbose-raise "TRY300", # try-consider-else "TRY301", # raise-within-try - "UP015", # redundant-open-modes "UP030", # format-literals "UP031", # printf-string-formatting "UP032", # f-string diff --git a/python/grass/grassdb/history.py b/python/grass/grassdb/history.py index 60b5459700d..d7c22eb36fc 100644 --- a/python/grass/grassdb/history.py +++ b/python/grass/grassdb/history.py @@ -81,9 +81,7 @@ def _read_from_plain_text(history_path): stores only executed commands.""" content_list = [] try: - with open( - history_path, encoding="utf-8", mode="r", errors="replace" - ) as file_history: + with open(history_path, encoding="utf-8", errors="replace") as file_history: content_list = [ {"command": line.strip(), "command_info": None} for line in file_history ] @@ -287,7 +285,7 @@ def _add_entry_to_JSON(history_path, entry): :param dict entry: entry consisting of 'command' and 'command_info' keys """ try: - with open(history_path, encoding="utf-8", mode="r") as file_history: + with open(history_path, encoding="utf-8") as file_history: existing_data = json.load(file_history) except (OSError, ValueError): existing_data = [] diff --git a/python/grass/gunittest/checkers.py b/python/grass/gunittest/checkers.py index fb46a1deb66..c63f6d08ff0 100644 --- a/python/grass/gunittest/checkers.py +++ b/python/grass/gunittest/checkers.py @@ -638,7 +638,7 @@ def text_file_md5( if prepend_lines: for line in prepend_lines: hasher.update(encode(line)) - with open(filename, "r") as f: + with open(filename) as f: for line in f: # replace platform newlines by standard newline if os.linesep != "\n": diff --git a/python/grass/gunittest/reporters.py b/python/grass/gunittest/reporters.py index 650480a234c..9535e07f871 100644 --- a/python/grass/gunittest/reporters.py +++ b/python/grass/gunittest/reporters.py @@ -51,7 +51,7 @@ def replace_in_file(file_path, pattern, repl): """ # using tmp file to store the replaced content tmp_file_path = file_path + ".tmp" - with open(file_path, "r") as old_file, open(tmp_file_path, "w") as new_file: + with open(file_path) as old_file, open(tmp_file_path, "w") as new_file: for line in old_file: new_file.write(re.sub(pattern=pattern, string=line, repl=repl)) # remove old file since it must not exist for rename/move diff --git a/python/grass/jupyter/interactivemap.py b/python/grass/jupyter/interactivemap.py index 085c2843fe7..d843ac3b6b6 100644 --- a/python/grass/jupyter/interactivemap.py +++ b/python/grass/jupyter/interactivemap.py @@ -178,7 +178,7 @@ def add_to(self, interactive_map): else: import ipyleaflet # pylint: disable=import-outside-toplevel - with open(self._filename, "r", encoding="utf-8") as file: + with open(self._filename, encoding="utf-8") as file: data = json.load(file) # allow using opacity directly to keep interface # consistent for both backends diff --git a/python/grass/pygrass/gis/__init__.py b/python/grass/pygrass/gis/__init__.py index 3f380368d28..d31bc31b972 100644 --- a/python/grass/pygrass/gis/__init__.py +++ b/python/grass/pygrass/gis/__init__.py @@ -430,7 +430,7 @@ def __iter__(self): def read(self): """Return the mapsets in the search path""" try: - with open(self.spath, "r") as f: + with open(self.spath) as f: lines = f.readlines() if lines: return [line.strip() for line in lines] diff --git a/python/grass/pygrass/modules/grid/grid.py b/python/grass/pygrass/modules/grid/grid.py index fb338ca973a..e0dbd309656 100644 --- a/python/grass/pygrass/modules/grid/grid.py +++ b/python/grass/pygrass/modules/grid/grid.py @@ -121,7 +121,7 @@ def read_gisrc(gisrc): ... genv['GISDBASE'])) True """ - with open(gisrc, "r") as gfile: + with open(gisrc) as gfile: gis = dict( [(k.strip(), v.strip()) for k, v in [row.split(":", 1) for row in gfile]] ) diff --git a/python/grass/pygrass/modules/interface/env.py b/python/grass/pygrass/modules/interface/env.py index ad6e4c4800e..1f0519d23c5 100644 --- a/python/grass/pygrass/modules/interface/env.py +++ b/python/grass/pygrass/modules/interface/env.py @@ -13,7 +13,7 @@ def get_env(): gisrc = os.environ.get("GISRC") if gisrc is None: raise RuntimeError("You are not in a GRASS session, GISRC not found.") - with open(gisrc, mode="r") as grc: + with open(gisrc) as grc: return dict( [ (k.strip(), v.strip()) diff --git a/python/grass/pygrass/raster/category.py b/python/grass/pygrass/raster/category.py index cfeb84ddde2..f439d51dcdf 100644 --- a/python/grass/pygrass/raster/category.py +++ b/python/grass/pygrass/raster/category.py @@ -299,7 +299,7 @@ def read_rules(self, filename, sep=":"): """ self.reset() - with open(filename, "r") as f: + with open(filename) as f: for row in f: cat = row.strip().split(sep) if len(cat) == 2: diff --git a/python/grass/pygrass/tests/set_mapset.py b/python/grass/pygrass/tests/set_mapset.py index f9d4a96fabf..105735efa5a 100644 --- a/python/grass/pygrass/tests/set_mapset.py +++ b/python/grass/pygrass/tests/set_mapset.py @@ -13,7 +13,7 @@ def read_gisrc(gisrcpath): - gisrc = open(gisrcpath, "r") + gisrc = open(gisrcpath) diz = {} for row in gisrc: key, val = row.split(":") diff --git a/python/grass/script/core.py b/python/grass/script/core.py index 40709a11e80..ee90a41d4ef 100644 --- a/python/grass/script/core.py +++ b/python/grass/script/core.py @@ -1066,7 +1066,7 @@ def _text_to_key_value_dict( {'a': ['Hello'], 'c': [1, 2, 3, 4, 5], 'b': [1.0], 'd': ['hello', 8, 0.1]} """ - text = open(filename, "r").readlines() + text = open(filename).readlines() kvdict = KeyValue() for line in text: @@ -1276,7 +1276,7 @@ def region_env(region3d=False, flags=None, env=None, **kwargs): windfile = os.path.join( gis_env["GISDBASE"], gis_env["LOCATION_NAME"], gis_env["MAPSET"], "WIND" ) - with open(windfile, "r") as fd: + with open(windfile) as fd: grass_region = "" for line in fd: key, value = (x.strip() for x in line.split(":", 1)) diff --git a/python/grass/script/utils.py b/python/grass/script/utils.py index 2868e3111e6..aa7d53375dd 100644 --- a/python/grass/script/utils.py +++ b/python/grass/script/utils.py @@ -91,8 +91,8 @@ def diff_files(filename_a, filename_b): import difflib differ = difflib.Differ() - fh_a = open(filename_a, "r") - fh_b = open(filename_b, "r") + fh_a = open(filename_a) + fh_b = open(filename_b) return list(differ.compare(fh_a.readlines(), fh_b.readlines())) diff --git a/python/grass/temporal/register.py b/python/grass/temporal/register.py index 0cd339946b9..8b7852ab557 100644 --- a/python/grass/temporal/register.py +++ b/python/grass/temporal/register.py @@ -161,7 +161,7 @@ def register_maps_in_space_time_dataset( if hasattr(file, "readline"): fd = file else: - fd = open(file, "r") + fd = open(file) line = True while True: diff --git a/python/grass/temporal/stds_import.py b/python/grass/temporal/stds_import.py index b8223c8ee83..006ee6a387e 100644 --- a/python/grass/temporal/stds_import.py +++ b/python/grass/temporal/stds_import.py @@ -372,7 +372,7 @@ def import_stds( fs = "|" maplist = [] mapset = get_current_mapset() - list_file = open(list_file_name, "r") + list_file = open(list_file_name) new_list_file = open(new_list_file_name, "w") # get number of lines to correctly form the suffix @@ -426,7 +426,7 @@ def import_stds( # Read the init file fs = "=" init = {} - init_file = open(init_file_name, "r") + init_file = open(init_file_name) while True: line = init_file.readline() if not line: diff --git a/raster/r.contour/testsuite/test_r_contour.py b/raster/r.contour/testsuite/test_r_contour.py index 9fc0fc17469..c9ee4c9876a 100644 --- a/raster/r.contour/testsuite/test_r_contour.py +++ b/raster/r.contour/testsuite/test_r_contour.py @@ -62,7 +62,7 @@ def test_raster_contour(self): self.assertModule("v.db.select", map=self.output, file="testReport") self.assertFileExists("testReport", msg="testReport file was not created") if os.path.isfile("testReport"): - file = open("testReport", "r") + file = open("testReport") fileData = file.read() self.assertMultiLineEqual(fileData, self.test_ref_str) file.close() @@ -87,7 +87,7 @@ def test_raster_contour_cut(self): self.assertModule("v.db.select", map=self.output + "_cut", file="testReportCut") self.assertFileExists("testReportCut", msg="testReportCut file was not created") if os.path.isfile("testReportCut"): - file = open("testReportCut", "r") + file = open("testReportCut") fileData = file.read() self.assertMultiLineEqual(fileData, self.test_ref_str) file.close() diff --git a/raster/r.in.gdal/testsuite/test_r_in_gdal.py b/raster/r.in.gdal/testsuite/test_r_in_gdal.py index 2390e9838cd..477ffca89c8 100644 --- a/raster/r.in.gdal/testsuite/test_r_in_gdal.py +++ b/raster/r.in.gdal/testsuite/test_r_in_gdal.py @@ -307,7 +307,7 @@ def test_netCDF_3d_5(self): test_gdal_import_map.0000000105 """ - text_from_file = open("map_names_file.txt", "r").read() + text_from_file = open("map_names_file.txt").read() self.assertLooksLike(map_list, text_from_file) diff --git a/raster/r.what/testsuite/test_r_what.py b/raster/r.what/testsuite/test_r_what.py index fcc312e6284..68bfdeea376 100644 --- a/raster/r.what/testsuite/test_r_what.py +++ b/raster/r.what/testsuite/test_r_what.py @@ -510,7 +510,7 @@ def test_raster_what_csv(self): ) self.assertFileExists(filename="result.csv", msg="CSV file was not created") if os.path.isfile("result.csv"): - file = open("result.csv", "r") + file = open("result.csv") fileData = file.read() self.assertLooksLike( actual=fileData, diff --git a/scripts/d.correlate/d.correlate.py b/scripts/d.correlate/d.correlate.py index af681cce545..1068733a11b 100755 --- a/scripts/d.correlate/d.correlate.py +++ b/scripts/d.correlate/d.correlate.py @@ -73,7 +73,7 @@ def main(): gcore.run_command("r.stats", flags="cnA", input=(i, j), stdout=ofile) ofile.close() - ifile = open(tmpfile, "r") + ifile = open(tmpfile) first = True for line in ifile: f = line.rstrip("\r\n").split(" ") @@ -95,7 +95,7 @@ def main(): p = gcore.feed_command("d.graph", color=color) ofile = p.stdin - ifile = open(tmpfile, "r") + ifile = open(tmpfile) for line in ifile: f = line.rstrip("\r\n").split(" ") x = float(f[0]) diff --git a/scripts/d.frame/d.frame.py b/scripts/d.frame/d.frame.py index e9b44b21650..ff77316f0ec 100755 --- a/scripts/d.frame/d.frame.py +++ b/scripts/d.frame/d.frame.py @@ -91,7 +91,7 @@ def check_monitor(): def read_monitor_file(monitor, ftype="env"): mfile = check_monitor_file(monitor, ftype) try: - fd = open(mfile, "r") + fd = open(mfile) except OSError as e: fatal(_("Unable to get monitor info. %s"), e) diff --git a/scripts/db.univar/db.univar.py b/scripts/db.univar/db.univar.py index f941be42140..97dfbdb7dbe 100755 --- a/scripts/db.univar/db.univar.py +++ b/scripts/db.univar/db.univar.py @@ -77,7 +77,7 @@ def cleanup(): def sortfile(infile, outfile): - inf = open(infile, "r") + inf = open(infile) outf = open(outfile, "w") if gs.find_program("sort", "--help"): diff --git a/scripts/g.extension.all/g.extension.all.py b/scripts/g.extension.all/g.extension.all.py index 43d50073178..1b0a2a88108 100644 --- a/scripts/g.extension.all/g.extension.all.py +++ b/scripts/g.extension.all/g.extension.all.py @@ -64,7 +64,7 @@ def get_extensions(): return [] # read XML file - fo = open(fXML, "r") + fo = open(fXML) try: tree = ET.fromstring(fo.read()) except Exception as e: diff --git a/scripts/g.search.modules/g.search.modules.py b/scripts/g.search.modules/g.search.modules.py index 574b8133a9e..cb40cbdced5 100755 --- a/scripts/g.search.modules/g.search.modules.py +++ b/scripts/g.search.modules/g.search.modules.py @@ -201,7 +201,7 @@ def _search_module( WXGUIDIR = os.path.join(os.getenv("GISBASE"), "gui", "wxpython") filename = os.path.join(WXGUIDIR, "xml", "module_items.xml") - menudata_file = open(filename, "r") + menudata_file = open(filename) menudata = ET.parse(menudata_file) menudata_file.close() @@ -212,7 +212,7 @@ def _search_module( if os.getenv("GRASS_ADDON_BASE"): filename_addons = os.path.join(os.getenv("GRASS_ADDON_BASE"), "modules.xml") if os.path.isfile(filename_addons): - addon_menudata_file = open(filename_addons, "r") + addon_menudata_file = open(filename_addons) addon_menudata = ET.parse(addon_menudata_file) addon_menudata_file.close() addon_items = addon_menudata.findall("task") @@ -221,7 +221,7 @@ def _search_module( # add system-wide installed addons to modules list filename_addons_s = os.path.join(os.getenv("GISBASE"), "modules.xml") if os.path.isfile(filename_addons_s): - addon_menudata_file_s = open(filename_addons_s, "r") + addon_menudata_file_s = open(filename_addons_s) addon_menudata_s = ET.parse(addon_menudata_file_s) addon_menudata_file_s.close() addon_items_s = addon_menudata_s.findall("task") diff --git a/scripts/r.in.wms/wms_gdal_drv.py b/scripts/r.in.wms/wms_gdal_drv.py index 69a49ca5429..830be2b593e 100644 --- a/scripts/r.in.wms/wms_gdal_drv.py +++ b/scripts/r.in.wms/wms_gdal_drv.py @@ -155,7 +155,7 @@ def _download(self): xml_file = self._createXML() # print xml file content for debug level 1 - file = open(xml_file, "r") + file = open(xml_file) gs.debug("WMS request XML:\n%s" % file.read(), 1) file.close() diff --git a/scripts/r.pack/r.pack.py b/scripts/r.pack/r.pack.py index bb3332101ee..5029f93c6d2 100644 --- a/scripts/r.pack/r.pack.py +++ b/scripts/r.pack/r.pack.py @@ -95,7 +95,7 @@ def main(): if map_file["file"]: vrt = os.path.join(map_file["file"], "vrt") if os.path.exists(vrt): - with open(vrt, "r") as f: + with open(vrt) as f: for r in f: map, mapset = r.split("@") map_basedir = os.path.sep.join( diff --git a/scripts/v.unpack/v.unpack.py b/scripts/v.unpack/v.unpack.py index 419e133b195..ea75d443b57 100644 --- a/scripts/v.unpack/v.unpack.py +++ b/scripts/v.unpack/v.unpack.py @@ -218,7 +218,7 @@ def main(): todb = dbconn["database"] # return the list of old connection for extract layer number and key - dbln = open(os.path.join(new_dir, "dbln"), "r") + dbln = open(os.path.join(new_dir, "dbln")) dbnlist = dbln.readlines() dbln.close() # check if dbf or sqlite directory exists diff --git a/temporal/t.rast.what/t.rast.what.py b/temporal/t.rast.what/t.rast.what.py index 39e63180abf..b3cec73a538 100755 --- a/temporal/t.rast.what/t.rast.what.py +++ b/temporal/t.rast.what/t.rast.what.py @@ -389,7 +389,7 @@ def one_point_per_row_output( file_name = output_files[count] gs.verbose(_("Transforming r.what output file %s") % (file_name)) map_list = output_time_list[count] - in_file = open(file_name, "r") + in_file = open(file_name) for line in in_file: line = line.split(separator) if vcat: @@ -466,7 +466,7 @@ def one_point_per_col_output( for count in range(len(output_files)): file_name = output_files[count] gs.verbose(_("Transforming r.what output file %s") % (file_name)) - in_file = open(file_name, "r") + in_file = open(file_name) lines = in_file.readlines() matrix = [] @@ -563,7 +563,7 @@ def one_point_per_timerow_output( file_name = output_files[count] gs.verbose("Transforming r.what output file %s" % (file_name)) map_list = output_time_list[count] - in_file = open(file_name, "r") + in_file = open(file_name) if write_header: if first is True: diff --git a/temporal/t.remove/t.remove.py b/temporal/t.remove/t.remove.py index b5c1164cef4..91fa58dde7a 100755 --- a/temporal/t.remove/t.remove.py +++ b/temporal/t.remove/t.remove.py @@ -102,7 +102,7 @@ def main(): # Read the dataset list from file if file: - fd = open(file, "r") + fd = open(file) line = True while True: diff --git a/temporal/t.unregister/t.unregister.py b/temporal/t.unregister/t.unregister.py index 7aef44ed12b..b39b7b9819f 100755 --- a/temporal/t.unregister/t.unregister.py +++ b/temporal/t.unregister/t.unregister.py @@ -108,7 +108,7 @@ def main(): # Read the map list from file if file: - fd = open(file, "r") + fd = open(file) line = True while True: From afbc3ae7b441575faa633ac7f409e3bda3c9dd9a Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 30 Sep 2024 23:38:10 +0000 Subject: [PATCH 2/7] CI(deps): Lock file maintenance (#4416) --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index fcda6ed01dd..51f61fb86f9 100644 --- a/flake.lock +++ b/flake.lock @@ -19,11 +19,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1726871744, - "narHash": "sha256-V5LpfdHyQkUF7RfOaDPrZDP+oqz88lTJrMT1+stXNwo=", + "lastModified": 1727648392, + "narHash": "sha256-VTlVv1nSxImFxY6RPQpNZxvEOQ0u5s1wBFDgixySNDo=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "a1d92660c6b3b7c26fb883500a80ea9d33321be2", + "rev": "4e0c36e4dd53f35d5a6385bdae88895ec5832f70", "type": "github" }, "original": { From e427da09ba2e56d6d75bdd1d8dc5235fc31d6384 Mon Sep 17 00:00:00 2001 From: Arohan Ajit Date: Mon, 30 Sep 2024 19:44:38 -0400 Subject: [PATCH 3/7] wxGUI: Fixed flake8 E722: bare 'except' in wxpython/gcp/ (#4392) --- .flake8 | 1 - gui/wxpython/gcp/manager.py | 14 -------------- 2 files changed, 15 deletions(-) diff --git a/.flake8 b/.flake8 index c3256ec22bf..ceee4512ca2 100644 --- a/.flake8 +++ b/.flake8 @@ -25,7 +25,6 @@ per-file-ignores = doc/python/m.distance.py: E501 doc/gui/wxpython/example/dialogs.py: F401 gui/scripts/d.wms.py: E501 - gui/wxpython/gcp/manager.py: E722 gui/wxpython/gui_core/*: E722 gui/wxpython/gui_core/dialogs.py: E722 gui/wxpython/gui_core/forms.py: E722 diff --git a/gui/wxpython/gcp/manager.py b/gui/wxpython/gcp/manager.py index 528d710f72c..3b6dd398b51 100644 --- a/gui/wxpython/gcp/manager.py +++ b/gui/wxpython/gcp/manager.py @@ -880,20 +880,6 @@ def OnSrcSelection(self, event): else: wx.FindWindowById(wx.ID_FORWARD).Enable(True) - try: - # set computational region to match selected map and zoom display - # to region - if maptype == "raster": - p = RunCommand("g.region", "raster=src_map") - elif maptype == "vector": - p = RunCommand("g.region", "vector=src_map") - - if p.returncode == 0: - print("returncode = ", str(p.returncode)) - self.parent.Map.region = self.parent.Map.GetRegion() - except: - pass - def OnTgtRastSelection(self, event): """Source map to display selected""" global tgt_map From 3e53e34a922c51fd84b39e2cb6569070cf8761eb Mon Sep 17 00:00:00 2001 From: Arohan Ajit Date: Mon, 30 Sep 2024 23:58:29 -0400 Subject: [PATCH 4/7] wxGUI: Fixed F841 in ii2t_manager.py (#4418) * fixed e722 in ii2t_manager * revert * fixed F841 in iit2t_manager.py * removed point from ii2t_mapdisplay * updated BusyInfo to use context manager --- gui/wxpython/image2target/ii2t_manager.py | 62 +++++++++----------- gui/wxpython/image2target/ii2t_mapdisplay.py | 2 - 2 files changed, 27 insertions(+), 37 deletions(-) diff --git a/gui/wxpython/image2target/ii2t_manager.py b/gui/wxpython/image2target/ii2t_manager.py index 06693926ec3..9284c3a2b2a 100644 --- a/gui/wxpython/image2target/ii2t_manager.py +++ b/gui/wxpython/image2target/ii2t_manager.py @@ -1781,22 +1781,20 @@ def OnGeorect(self, event): else: flags = "a" - busy = wx.BusyInfo(_("Rectifying images, please wait..."), parent=self) - wx.GetApp().Yield() - - ret, msg = RunCommand( - "i.ortho.rectify", - parent=self, - getErrorMsg=True, - quiet=True, - group=self.xygroup, - extension=self.extension, - method=self.gr_method, - angle=self.grwiz.cam_angle, - flags=flags, - ) + with wx.BusyInfo(_("Rectifying images, please wait..."), parent=self): + wx.GetApp().Yield() - del busy + ret, msg = RunCommand( + "i.ortho.rectify", + parent=self, + getErrorMsg=True, + quiet=True, + group=self.xygroup, + extension=self.extension, + method=self.gr_method, + angle=self.grwiz.cam_angle, + flags=flags, + ) # provide feedback on failure if ret != 0: @@ -1828,23 +1826,21 @@ def OnGeorect(self, event): ) ret = msg = "" - busy = wx.BusyInfo( + with wx.BusyInfo( _("Rectifying vector map <%s>, please wait...") % vect, parent=self - ) - wx.GetApp().Yield() - - ret, msg = RunCommand( - "v.rectify", - parent=self, - getErrorMsg=True, - quiet=True, - input=vect, - output=self.outname, - group=self.xygroup, - order=self.gr_order, - ) - - del busy + ): + wx.GetApp().Yield() + + ret, msg = RunCommand( + "v.rectify", + parent=self, + getErrorMsg=True, + quiet=True, + input=vect, + output=self.outname, + group=self.xygroup, + order=self.gr_order, + ) # provide feedback on failure if ret != 0: @@ -1971,7 +1967,6 @@ def OnGROrder(self, event): elif self.gr_order == 2: minNumOfItems = 6 - diff = 6 - numOfItems # self.SetStatusText(_( # "Insufficient points, 6+ points needed for 2nd order")) @@ -2270,7 +2265,6 @@ def OnZoomToTarget(self, event): def OnZoomMenuGCP(self, event): """Popup Zoom menu""" - point = wx.GetMousePosition() zoommenu = Menu() # Add items to the menu @@ -3376,7 +3370,6 @@ def UpdateSettings(self): srcrenderVector = False tgtrender = False tgtrenderVector = False - reload_target = False if self.new_src_map != src_map: # remove old layer layers = self.parent.grwiz.SrcMap.GetListOfLayers() @@ -3414,7 +3407,6 @@ def UpdateSettings(self): del layers[0] layers = self.parent.grwiz.TgtMap.GetListOfLayers() # self.parent.grwiz.TgtMap.DeleteAllLayers() - reload_target = True tgt_map["raster"] = self.new_tgt_map["raster"] tgt_map["vector"] = self.new_tgt_map["vector"] diff --git a/gui/wxpython/image2target/ii2t_mapdisplay.py b/gui/wxpython/image2target/ii2t_mapdisplay.py index c148eb314d2..9ee3b77d118 100644 --- a/gui/wxpython/image2target/ii2t_mapdisplay.py +++ b/gui/wxpython/image2target/ii2t_mapdisplay.py @@ -474,7 +474,6 @@ def PrintMenu(self, event): """ Print options and output menu for map display """ - point = wx.GetMousePosition() printmenu = Menu() # Add items to the menu setup = wx.MenuItem(printmenu, wx.ID_ANY, _("Page setup")) @@ -518,7 +517,6 @@ def SaveDisplayRegion(self, event): def OnZoomMenu(self, event): """Popup Zoom menu""" - point = wx.GetMousePosition() zoommenu = Menu() # Add items to the menu From 25619dd06a5dba16414d279c9d895b7e7f444450 Mon Sep 17 00:00:00 2001 From: Arohan Ajit Date: Tue, 1 Oct 2024 01:36:16 -0400 Subject: [PATCH 5/7] wxGUI: Fix E722 do not use bare 'except' warnings in `gui_core/` (#4396) * updated 722 from gui_core * updated flake8 * updated ghelp v2 * updated ghelp v3 * Update gui/wxpython/gui_core/dialogs.py Co-authored-by: Anna Petrasova * removed prints * Update dialogs.py * updated indexerror * updated exception * Update .flake8 * Update .flake8 --------- Co-authored-by: Anna Petrasova --- .flake8 | 6 ------ gui/wxpython/gui_core/dialogs.py | 4 ++-- gui/wxpython/gui_core/forms.py | 2 +- gui/wxpython/gui_core/ghelp.py | 14 +++++++------- gui/wxpython/gui_core/gselect.py | 2 +- gui/wxpython/gui_core/widgets.py | 2 +- 6 files changed, 12 insertions(+), 18 deletions(-) diff --git a/.flake8 b/.flake8 index ceee4512ca2..580aa6670a1 100644 --- a/.flake8 +++ b/.flake8 @@ -25,12 +25,6 @@ per-file-ignores = doc/python/m.distance.py: E501 doc/gui/wxpython/example/dialogs.py: F401 gui/scripts/d.wms.py: E501 - gui/wxpython/gui_core/*: E722 - gui/wxpython/gui_core/dialogs.py: E722 - gui/wxpython/gui_core/forms.py: E722 - gui/wxpython/gui_core/ghelp.py: E722 - gui/wxpython/gui_core/gselect.py: E722 - gui/wxpython/gui_core/widgets.py: E722 gui/wxpython/image2target/*: F841, E722 gui/wxpython/image2target/g.gui.image2target.py: E501, F841 gui/wxpython/iscatt/*: F841, E722, F405, F403 diff --git a/gui/wxpython/gui_core/dialogs.py b/gui/wxpython/gui_core/dialogs.py index f7c7711cadf..cd2a8dcc24d 100644 --- a/gui/wxpython/gui_core/dialogs.py +++ b/gui/wxpython/gui_core/dialogs.py @@ -1213,7 +1213,7 @@ def _filter(self, data): try: if re.compile(self.flt_pattern).search(dt): flt_data.append(dt) - except: + except re.error: pass return flt_data @@ -1656,7 +1656,7 @@ def OnFilter(self, event): try: if re.compile(event.GetString()).search(layer): list.append(layer) - except: + except re.error: pass list = naturally_sorted(list) diff --git a/gui/wxpython/gui_core/forms.py b/gui/wxpython/gui_core/forms.py index 1ef623feaf7..c1123497abf 100644 --- a/gui/wxpython/gui_core/forms.py +++ b/gui/wxpython/gui_core/forms.py @@ -2016,7 +2016,7 @@ def __init__(self, parent, giface, task, id=wx.ID_ANY, frame=None, *args, **kwar # check wildcard try: fExt = os.path.splitext(p.get("key_desc", ["*.*"])[0])[1] - except: + except IndexError: fExt = None if not fExt: fMask = "*" diff --git a/gui/wxpython/gui_core/ghelp.py b/gui/wxpython/gui_core/ghelp.py index 6713dbcc0a3..0c4f6cdadfb 100644 --- a/gui/wxpython/gui_core/ghelp.py +++ b/gui/wxpython/gui_core/ghelp.py @@ -566,15 +566,15 @@ def _langString(self, k, v): allStr = "%s :" % k.upper() try: allStr += _(" %d translated") % v["good"] - except: + except KeyError: pass try: allStr += _(" %d fuzzy") % v["fuzzy"] - except: + except KeyError: pass try: allStr += _(" %d untranslated") % v["bad"] - except: + except KeyError: pass return allStr @@ -589,7 +589,7 @@ def _langBox(self, par, k, v): ) tgood.SetForegroundColour(wx.Colour(35, 142, 35)) langBox.Add(tgood) - except: + except KeyError: tgood = StaticText(parent=par, id=wx.ID_ANY, label="") langBox.Add(tgood) try: @@ -598,7 +598,7 @@ def _langBox(self, par, k, v): ) tfuzzy.SetForegroundColour(wx.Colour(255, 142, 0)) langBox.Add(tfuzzy) - except: + except KeyError: tfuzzy = StaticText(parent=par, id=wx.ID_ANY, label="") langBox.Add(tfuzzy) try: @@ -607,7 +607,7 @@ def _langBox(self, par, k, v): ) tbad.SetForegroundColour(wx.Colour(255, 0, 0)) langBox.Add(tbad) - except: + except KeyError: tbad = StaticText(parent=par, id=wx.ID_ANY, label="") langBox.Add(tbad) return langBox @@ -844,7 +844,7 @@ def fillContentsFromFile(self, htmlFile, skipDescription=True): contents.append(line) self.SetPage("".join(contents)) self.loaded = True - except: # The Manual file was not found + except Exception: # The Manual file was not found self.loaded = False diff --git a/gui/wxpython/gui_core/gselect.py b/gui/wxpython/gui_core/gselect.py index af71cc4f550..ec873f60eb4 100644 --- a/gui/wxpython/gui_core/gselect.py +++ b/gui/wxpython/gui_core/gselect.py @@ -484,7 +484,7 @@ def GetElementList(self, elements=None, exclude=False): try: self.seltree.EnsureVisible(item) self.seltree.SelectItem(item) - except: + except Exception: pass def _getElementList(self, element, mapsets=None, elements=None, exclude=False): diff --git a/gui/wxpython/gui_core/widgets.py b/gui/wxpython/gui_core/widgets.py index 5f2582f9b1e..dc9041e3578 100644 --- a/gui/wxpython/gui_core/widgets.py +++ b/gui/wxpython/gui_core/widgets.py @@ -752,7 +752,7 @@ def _validate(self, win): if text: try: datetime.strptime(text, "%Y-%m-%d") - except: + except ValueError: self._notvalid() return False From 63829498814e0716fb6d26fe1442d81ddd82cb9d Mon Sep 17 00:00:00 2001 From: ShubhamDesai <42180509+ShubhamDesai@users.noreply.github.com> Date: Tue, 1 Oct 2024 10:48:54 -0400 Subject: [PATCH 6/7] v.generalize: Fix Resource Leak issue in displacement.c (#4422) * fix Resource Leak * fix for points --- vector/v.generalize/displacement.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vector/v.generalize/displacement.c b/vector/v.generalize/displacement.c index bc7a3f15170..a4d599080e4 100644 --- a/vector/v.generalize/displacement.c +++ b/vector/v.generalize/displacement.c @@ -310,6 +310,8 @@ int snakes_displacement(struct Map_info *In, struct Map_info *Out, matrix_free(&fy); matrix_free(&dx_old); matrix_free(&dy_old); + Vect_destroy_cats_struct(Cats); + Vect_destroy_line_struct(Points); return 0; } From 13cda735ce297be1f45aca9da5c9995413a94abb Mon Sep 17 00:00:00 2001 From: Arohan Ajit Date: Tue, 1 Oct 2024 14:34:29 -0400 Subject: [PATCH 7/7] wxGUI: Fixed unused 'wizard' variable - F841 in image2target/ (#4400) --- .flake8 | 2 +- gui/wxpython/image2target/g.gui.image2target.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.flake8 b/.flake8 index 580aa6670a1..d704112048f 100644 --- a/.flake8 +++ b/.flake8 @@ -26,7 +26,7 @@ per-file-ignores = doc/gui/wxpython/example/dialogs.py: F401 gui/scripts/d.wms.py: E501 gui/wxpython/image2target/*: F841, E722 - gui/wxpython/image2target/g.gui.image2target.py: E501, F841 + gui/wxpython/image2target/g.gui.image2target.py: E501 gui/wxpython/iscatt/*: F841, E722, F405, F403 gui/wxpython/lmgr/frame.py: F841, E722 # layertree still includes some formatting issues (it is ignored by Black) diff --git a/gui/wxpython/image2target/g.gui.image2target.py b/gui/wxpython/image2target/g.gui.image2target.py index 37d33c2d70e..e2704dc371b 100755 --- a/gui/wxpython/image2target/g.gui.image2target.py +++ b/gui/wxpython/image2target/g.gui.image2target.py @@ -64,7 +64,8 @@ def main(): app = wx.App() - wizard = GCPWizard(parent=None, giface=StandaloneGrassInterface()) + GCPWizard(parent=None, giface=StandaloneGrassInterface()) + app.MainLoop()