Skip to content

Commit

Permalink
ruff: fix / ignore TRY errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Mar 5, 2024
1 parent dc17df5 commit 25ea71c
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 27 deletions.
12 changes: 7 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
target-version = "py310"
line-length = 88

# see https://docs.astral.sh/ruff/rules/
lint.select = [
"F", # Pyflakes
"E", # pycodestyle Error
Expand All @@ -14,7 +15,7 @@ lint.select = [
"UP", # pyupgrade
"YTT", # flake8-2020
# "ANN", # flake8-annotationsq, still gives errors for `self`
# ASYNC, # flake8-async
# "ASYNC", # flake8-async
"TRIO", # flake8-trio
# "S", # flake8-bandit
"BLE", # flake8-blind-except
Expand Down Expand Up @@ -54,12 +55,12 @@ lint.select = [
# "PD", # pandas-vet: full of false positives
"PGH", # pygrep-hooks
# "PL", # Pylint
# "TRY", # tryceratops, they all sound BS
"TRY", # tryceratops, some are BS
# "FLY", # flynt
"NPY", # NumPy-specific rules
"AIR", # Airflow
"PERF", # Perflint
# "FURB", # refurb --preview
# "FURB", # refurb, ruff --preview
"LOG", # flake8-logging
"RUF", # Ruff-specific rules
]
Expand Down Expand Up @@ -99,9 +100,9 @@ lint.ignore = [
"RUF005", # Consider `[*_list, x]` instead of concatenation
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
"RUF100", # Unused `noqa` directive (non-enabled: ...)
"TRY003", # Avoid specifying long messages outside the exception class, ???
"TRY400", # Use `logging.exception` instead of `logging.error`

"TRY003", # BS: Avoid specifying long messages outside the exception class
"TRY400", # BS: Use `logging.exception` instead of `logging.error`
"SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass
"SIM108", # Use ternary operator {contents} instead of if-else-block
"SIM117", # Use a single with statement with multiple contexts...
Expand All @@ -120,6 +121,7 @@ lint.ignore = [

# Allow autofix for all enabled rules (when `--fix`) is provided.
lint.fixable = [
"TRY", # tryceratops
"ANN",
"C408", # Unnecessary `dict` call (rewrite as a literal)
"COM",
Expand Down
2 changes: 1 addition & 1 deletion scal3/event_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -4614,7 +4614,7 @@ def _exportToIcsFpEvent(
vevent += "\n".join(parts)
fp.write(vevent)
else:
raise RuntimeError
raise TypeError(f"invalid type {type(occur)} for occur")

def exportToIcsFp(self, fp: "io.TextIOBase") -> None:
currentTimeStamp = ics.getIcsTimeByEpoch(now())
Expand Down
4 changes: 2 additions & 2 deletions scal3/locale_man.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ def setData(self, data: dict):
try:
with open(fpath, encoding="utf-8") as fp:
data = jsonToData(fp.read())
except Exception as e:
except Exception:
log.error(f"failed to load json file {fpath}")
raise e
raise
langObj = LangData(fpath)
langObj.setData(data)
langDict[langObj.code] = langObj
Expand Down
4 changes: 2 additions & 2 deletions scal3/os_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def kill(pid, signal=0):
# no permissions
if e.errno == 1:
return False
raise e
raise


def dead(pid):
Expand All @@ -118,7 +118,7 @@ def dead(pid):
# pid is not a child
if e.errno == 10:
return False
raise e
raise
return dead


Expand Down
8 changes: 4 additions & 4 deletions scal3/s_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ def load(cls, fs: FileSystem, *args):
with fs.open(fpath) as fp:
jsonStr = fp.read()
data = jsonToData(jsonStr)
except Exception as e:
except Exception:
if not cls.skipLoadExceptions:
raise e
raise
else:
if not cls.skipLoadNoFile:
raise FileNotFoundError(f"{fpath} : file not found")
Expand Down Expand Up @@ -369,10 +369,10 @@ def load(cls, fs: FileSystem, *args):
except FileNotFoundError:
if not cls.skipLoadNoFile:
raise FileNotFoundError(f"{_file} : file not found") from None
except Exception as e:
except Exception:
if not cls.skipLoadExceptions:
log.error(f'error while opening json file "{_file}"')
raise e
raise
else:
lastEpoch, lastHash = updateBasicDataFromBson(data, _file, cls.name, fs)

Expand Down
6 changes: 3 additions & 3 deletions scal3/ui_gtk/event/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2292,7 +2292,7 @@ def editTrash(self, _menuItem: "gtk.MenuItem | None" = None) -> None:
def moveUp(self, path: list[int]) -> None:
srcIter = self.treeModel.get_iter(path)
if not isinstance(path, list):
raise RuntimeError(f"invalid {path = }")
raise TypeError(f"invalid {path = }")
if len(path) == 1:
if path[0] == 0:
return
Expand Down Expand Up @@ -2336,7 +2336,7 @@ def moveUp(self, path: list[int]) -> None:
newGroup.save()
ui.eventUpdateQueue.put("r", parentObj, self)
else:
raise RuntimeError(f"invalid tree path {path}")
raise ValueError(f"invalid tree path {path}")
newPath = self.treeModel.get_path(srcIter)
if len(path) == 2:
self.treev.expand_to_path(newPath)
Expand All @@ -2345,7 +2345,7 @@ def moveUp(self, path: list[int]) -> None:

def moveDown(self, path: list[int]) -> None:
if not isinstance(path, list):
raise RuntimeError(f"invalid {path = }")
raise TypeError(f"invalid {path = }")
srcIter = self.treeModel.get_iter(path)
if len(path) == 1:
if self.getRowId(srcIter) == -1:
Expand Down
2 changes: 1 addition & 1 deletion scal3/ui_gtk/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def getWidget(self):
return self._item
item = self.initializer()
if not isinstance(item, gtk.Widget):
raise ValueError(f"initializer returned non-widget: {type(item)}")
raise TypeError(f"initializer returned non-widget: {type(item)}")
item.enableParam = self.enableParam
if item.enableParam:
item.enable = getattr(ui, item.enableParam)
Expand Down
2 changes: 0 additions & 2 deletions scal3/ui_gtk/mywidgets/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ def waitingDo(self, func, *args, **kwargs):
return result
try:
result = func(*args, **kwargs)
except Exception as e:
raise e
finally:
self.endWaiting()
return result
2 changes: 1 addition & 1 deletion scal3/ui_gtk/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def addPage(self, page: StackPage):
raise ValueError(f"addPage: duplicate {pagePath=}")

if not isinstance(widget, gtk.Widget):
raise ValueError(f"invalid {widget=}, {pagePath=}")
raise TypeError(f"invalid {widget=}, {pagePath=}")

widget.show()
if self._header and parentName:
Expand Down
8 changes: 4 additions & 4 deletions scal3/ui_gtk/starcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,18 @@ def createItems(self):
fromlist=["CalObj"],
)
CalObj = module.CalObj
except RuntimeError as e:
raise e
except RuntimeError:
raise
except Exception:
log.error(f"error importing mainWinItem {name}")
log.exception("")
# raise e
continue
try:
item = CalObj(win)
except Exception as e:
except Exception:
log.error(f"{name=}, {module=}")
raise e
raise
item.enable = enable
# modify_bg_all(
# item,
Expand Down
4 changes: 2 additions & 2 deletions scal3/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def __setitem__(self, arg: "int | str", value) -> None:
self.keyList.append(arg)
dict.__setitem__(self, arg, value)
else:
raise ValueError(
raise TypeError(
"Bad type argument given to StrOrderedDict.__setitem__"
f": {type(arg)}",
)
Expand All @@ -178,7 +178,7 @@ def __delitem__(self, arg: "int | str | slice") -> None:
dict.__delitem__(self, key)
self.keyList.__delitem__(arg)
else:
raise ValueError(
raise TypeError(
"Bad type argument given to StrOrderedDict.__delitem__"
f": {type(arg)}",
)
Expand Down

0 comments on commit 25ea71c

Please sign in to comment.