Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Fix superfluous-else-return (RET505) #4459

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 28 additions & 29 deletions gui/wxpython/animation/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1548,37 +1548,36 @@ def _export_file_validation(self, filebrowsebtn, file_path, file_postfix):
if not file_path:
GError(parent=self, message=_("Export file is missing."))
return False
else:
if not file_path.endswith(file_postfix):
filebrowsebtn.SetValue(file_path + file_postfix)
file_path += file_postfix

base_dir = os.path.dirname(file_path)
if not os.path.exists(base_dir):
GError(
parent=self,
message=file_path_does_not_exist_err_message.format(
base_dir=base_dir,
),
)
return False
if not file_path.endswith(file_postfix):
filebrowsebtn.SetValue(file_path + file_postfix)
file_path += file_postfix

if os.path.exists(file_path):
overwrite_dlg = wx.MessageDialog(
self.GetParent(),
message=_(
"Exported animation file <{file}> exists. "
"Do you want to overwrite it?"
).format(
file=file_path,
),
caption=_("Overwrite?"),
style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION,
)
if overwrite_dlg.ShowModal() != wx.ID_YES:
overwrite_dlg.Destroy()
return False
base_dir = os.path.dirname(file_path)
if not os.path.exists(base_dir):
GError(
parent=self,
message=file_path_does_not_exist_err_message.format(
base_dir=base_dir,
),
)
return False

if os.path.exists(file_path):
overwrite_dlg = wx.MessageDialog(
self.GetParent(),
message=_(
"Exported animation file <{file}> exists. "
"Do you want to overwrite it?"
).format(
file=file_path,
),
caption=_("Overwrite?"),
style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION,
)
if overwrite_dlg.ShowModal() != wx.ID_YES:
overwrite_dlg.Destroy()
return False
overwrite_dlg.Destroy()

return True

Expand Down
5 changes: 2 additions & 3 deletions gui/wxpython/animation/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,8 @@ def LoadOverlay(self, cmd):

if returncode == 0:
return BitmapFromImage(autoCropImageFromFile(filename))
else:
os.remove(filename)
raise GException(messages)
os.remove(filename)
raise GException(messages)


class BitmapRenderer:
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/animation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ def validateTimeseriesName(timeseries, etype="strds"):
nameShort, mapset = timeseries.split("@", 1)
if nameShort in trastDict[mapset]:
return timeseries
else:
raise GException(_("Space time dataset <%s> not found.") % timeseries)
raise GException(_("Space time dataset <%s> not found.") % timeseries)

mapsets = tgis.get_tgis_c_library_interface().available_mapsets()
for mapset in mapsets:
Expand Down
12 changes: 5 additions & 7 deletions gui/wxpython/core/gcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,10 @@ def kill(self):

handle = win32api.OpenProcess(1, 0, self.pid)
return win32api.TerminateProcess(handle, 0) != 0
else:
try:
os.kill(-self.pid, signal.SIGTERM) # kill whole group
except OSError:
pass
try:
os.kill(-self.pid, signal.SIGTERM) # kill whole group
except OSError:
pass

if sys.platform == "win32":

Expand Down Expand Up @@ -750,8 +749,7 @@ def RunCommand(
if not read:
if not getErrorMsg:
return ret
else:
return ret, _formatMsg(stderr)
return ret, _formatMsg(stderr)

if stdout:
Debug.msg(3, "gcmd.RunCommand(): return stdout\n'%s'" % stdout)
Expand Down
199 changes: 98 additions & 101 deletions gui/wxpython/core/gconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,114 +552,111 @@ def RunCmd(
wx.PostEvent(self, event)
return

else:
# other GRASS commands (r|v|g|...)
try:
task = GUI(show=None).ParseCommand(command)
except GException as e:
GError(parent=self._guiparent, message=str(e), showTraceback=False)
return

hasParams = False
if task:
options = task.get_options()
hasParams = options["params"] and options["flags"]
# check for <input>=-
for p in options["params"]:
if (
p.get("prompt", "") == "input"
and p.get("element", "") == "file"
and p.get("age", "new") == "old"
and p.get("value", "") == "-"
):
GError(
parent=self._guiparent,
message=_(
"Unable to run command:\n%(cmd)s\n\n"
"Option <%(opt)s>: read from standard input is not "
"supported by wxGUI"
)
% {"cmd": " ".join(command), "opt": p.get("name", "")},
)
return

if len(command) == 1:
if command[0].startswith("g.gui."):
import inspect
import importlib.util
import importlib.machinery
# other GRASS commands (r|v|g|...)
try:
task = GUI(show=None).ParseCommand(command)
except GException as e:
GError(parent=self._guiparent, message=str(e), showTraceback=False)
return

def load_source(modname, filename):
loader = importlib.machinery.SourceFileLoader(
modname, filename
)
spec = importlib.util.spec_from_file_location(
modname, filename, loader=loader
)
module = importlib.util.module_from_spec(spec)
# Module is always executed and not cached in sys.modules.
# Uncomment the following line to cache the module.
# sys.modules[module.__name__] = module
loader.exec_module(module)
return module

pyFile = command[0]
if sys.platform == "win32":
pyFile += ".py"
pyPath = os.path.join(os.environ["GISBASE"], "scripts", pyFile)
if not os.path.exists(pyPath):
pyPath = os.path.join(
os.environ["GRASS_ADDON_BASE"], "scripts", pyFile
)
if not os.path.exists(pyPath):
GError(
parent=self._guiparent,
message=_("Module <%s> not found.") % command[0],
hasParams = False
if task:
options = task.get_options()
hasParams = options["params"] and options["flags"]
# check for <input>=-
for p in options["params"]:
if (
p.get("prompt", "") == "input"
and p.get("element", "") == "file"
and p.get("age", "new") == "old"
and p.get("value", "") == "-"
):
GError(
parent=self._guiparent,
message=_(
"Unable to run command:\n%(cmd)s\n\n"
"Option <%(opt)s>: read from standard input is not "
"supported by wxGUI"
)
pymodule = load_source(command[0].replace(".", "_"), pyPath)
pymain = inspect.getfullargspec(pymodule.main)
if pymain and "giface" in pymain.args:
pymodule.main(self._giface)
return

# no arguments given
if hasParams and not isinstance(self._guiparent, FormNotebook):
# also parent must be checked, see #3135 for details
try:
GUI(
parent=self._guiparent, giface=self._giface
).ParseCommand(command)
self.UpdateHistory(status=Status.SUCCESS)
except GException as e:
print(e, file=sys.stderr)
% {"cmd": " ".join(command), "opt": p.get("name", "")},
)
return

if len(command) == 1:
if command[0].startswith("g.gui."):
import inspect
import importlib.util
import importlib.machinery

def load_source(modname, filename):
loader = importlib.machinery.SourceFileLoader(modname, filename)
spec = importlib.util.spec_from_file_location(
modname, filename, loader=loader
)
module = importlib.util.module_from_spec(spec)
# Module is always executed and not cached in sys.modules.
# Uncomment the following line to cache the module.
# sys.modules[module.__name__] = module
loader.exec_module(module)
return module

pyFile = command[0]
if sys.platform == "win32":
pyFile += ".py"
pyPath = os.path.join(os.environ["GISBASE"], "scripts", pyFile)
if not os.path.exists(pyPath):
pyPath = os.path.join(
os.environ["GRASS_ADDON_BASE"], "scripts", pyFile
)
if not os.path.exists(pyPath):
GError(
parent=self._guiparent,
message=_("Module <%s> not found.") % command[0],
)
pymodule = load_source(command[0].replace(".", "_"), pyPath)
pymain = inspect.getfullargspec(pymodule.main)
if pymain and "giface" in pymain.args:
pymodule.main(self._giface)
return

if env:
env = env.copy()
else:
env = os.environ.copy()
# activate computational region (set with g.region)
# for all non-display commands.
if compReg and "GRASS_REGION" in env:
del env["GRASS_REGION"]
# no arguments given
if hasParams and not isinstance(self._guiparent, FormNotebook):
# also parent must be checked, see #3135 for details
try:
GUI(parent=self._guiparent, giface=self._giface).ParseCommand(
command
)
self.UpdateHistory(status=Status.SUCCESS)
except GException as e:
print(e, file=sys.stderr)

# process GRASS command with argument
self.cmdThread.RunCmd(
command,
stdout=self.cmdStdOut,
stderr=self.cmdStdErr,
onDone=onDone,
onPrepare=onPrepare,
userData=userData,
addLayer=addLayer,
env=env,
notification=notification,
)
self.cmdOutputTimer.Start(50)
return

if env:
env = env.copy()
else:
env = os.environ.copy()
# activate computational region (set with g.region)
# for all non-display commands.
if compReg and "GRASS_REGION" in env:
del env["GRASS_REGION"]

# process GRASS command with argument
self.cmdThread.RunCmd(
command,
stdout=self.cmdStdOut,
stderr=self.cmdStdErr,
onDone=onDone,
onPrepare=onPrepare,
userData=userData,
addLayer=addLayer,
env=env,
notification=notification,
)
self.cmdOutputTimer.Start(50)

# we don't need to change computational region settings
# because we work on a copy
# we don't need to change computational region settings
# because we work on a copy
else:
# Send any other command to the shell. Send output to
# console output window
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/core/gthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ def __run(self):
def globaltrace(self, frame, event, arg):
if event == "call":
return self.localtrace
else:
return None
return None

def localtrace(self, frame, event, arg):
if self.terminate:
Expand Down
7 changes: 3 additions & 4 deletions gui/wxpython/core/menutree.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,9 @@ def GetModel(self, separators=False):
"""
if separators:
return copy.deepcopy(self.model)
else:
model = copy.deepcopy(self.model)
removeSeparators(model)
return model
model = copy.deepcopy(self.model)
removeSeparators(model)
return model

def PrintTree(self, fh):
for child in self.model.root.children:
Expand Down
12 changes: 4 additions & 8 deletions gui/wxpython/core/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,8 @@ def GetCmd(self, string=False):
scmd.append(utils.GetCmdString(c))

return ";".join(scmd)
else:
return utils.GetCmdString(self.cmd)
else:
return self.cmd
return utils.GetCmdString(self.cmd)
return self.cmd

def GetType(self):
"""Get map layer type"""
Expand Down Expand Up @@ -462,8 +460,7 @@ def _render(self, cmd, env):
stdout, stderr = p.communicate()
if p.returncode:
return grass.decode(stderr)
else:
return None
return None

def Abort(self):
"""Abort rendering process"""
Expand Down Expand Up @@ -1690,8 +1687,7 @@ def GetOverlay(self, id, list=False):
if not list:
if len(ovl) != 1:
return None
else:
return ovl[0]
return ovl[0]

return ovl

Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ def color(item):
return [color(e) for e in item]
if isinstance(item, dict):
return {key: color(value) for key, value in item.items()}
else:
return item
return item

return super().iterencode(color(obj))

Expand Down
Loading
Loading