From 473c84fe22a18a8730cb4015a5affe894d69a733 Mon Sep 17 00:00:00 2001 From: Saeed Rasooli Date: Wed, 1 Jan 2025 04:15:44 +0330 Subject: [PATCH] update pyproject.toml and fix ruff refurb errors --- pyproject.toml | 16 ++++++++-------- scal3/event_lib.py | 3 +-- scal3/graph_utils.py | 4 +--- scal3/os_utils.py | 2 +- scal3/ui_gtk/customize.py | 2 +- scal3/ui_gtk/event/__init__.py | 16 ++-------------- scal3/ui_gtk/mainwin_items/monthCal.py | 10 ++-------- scal3/ui_gtk/starcal.py | 7 +------ scal3/ui_gtk/statusBar.py | 2 +- 9 files changed, 18 insertions(+), 44 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 41e678fd2..2add0f6f9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,6 @@ lint.select = [ "W", # pycodestyle Warning # "C90", # mccabe: C901: {name} is too complex ({complexity}) "I", # isort: unsorted-imports, missing-required-import - # "N", # pep8-naming "D", # pydocstyle "B", # flake8-bugbear "UP", # pyupgrade @@ -20,8 +19,8 @@ lint.select = [ # "S", # flake8-bandit "BLE", # flake8-blind-except # "FBT", # flake8-boolean-trap - # "B", flake8-bugbear - # "A", # flake8-builtins + "B", # flake8-bugbear + "A", # flake8-builtins "COM", # flake8-commas # "CPY", # flake8-copyright --preview "C4", # flake8-comprehensions @@ -32,7 +31,6 @@ lint.select = [ "EXE", # flake8-executable "FA", # flake8-future-annotations "ISC", # flake8-implicit-str-concat - # "G", # flake8-logging-format, non-sense! "INP", # flake8-no-pep420 "PIE", # flake8-pie # "T20", # flake8-print @@ -49,18 +47,16 @@ lint.select = [ "INT", # flake8-gettext "ARG", # flake8-unused-arguments # "PTH", # flake8-use-pathlib - # "TD", # flake8-todos - # "FIX", # flake8-fixme: just shows me FIXMEs and TODOs # "ERA", # eradicate # "PD", # pandas-vet: full of false positives "PGH", # pygrep-hooks "PL", # Pylint "TRY", # tryceratops, some are BS - # "FLY", # flynt + "FLY", # flynt "NPY", # NumPy-specific rules "AIR", # Airflow "PERF", # Perflint - # "FURB", # refurb, ruff --preview + "FURB", # refurb "LOG", # flake8-logging "RUF", # Ruff-specific rules ] @@ -69,6 +65,8 @@ lint.select = [ # To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding them to the `ignore` configuration. lint.ignore = [ + "FURB189", # Subclassing `list` can be error prone, use `collections.UserList` instead + "FURB103", # `open` and `write` should be replaced by `Path(...)....` "PYI024", # Use `typing.NamedTuple` instead of `collections.namedtuple` "PLC0206", # Extracting value from dictionary without calling `.items()` @@ -203,6 +201,8 @@ lint.dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" "PYI024", # Use `typing.NamedTuple` instead of `collections.namedtuple` ] +"tools/afghanistan-events.py" = ["FLY"] + [tool.ruff.format] quote-style = "double" indent-style = "tab" diff --git a/scal3/event_lib.py b/scal3/event_lib.py index 53c3e11cb..3d047272d 100644 --- a/scal3/event_lib.py +++ b/scal3/event_lib.py @@ -301,8 +301,7 @@ def do_removeUnusedObjects(): if not history: log.error(f"No history in file: {fpath}") continue - for _revTime, revHash in history: - hashSet.add(revHash) + hashSet.update({revHash for _revTime, revHash in history}) log.info(f"Found {len(hashSet)} used objects") removedCount = 0 diff --git a/scal3/graph_utils.py b/scal3/graph_utils.py index 69f42a0dc..ce0ce84b8 100644 --- a/scal3/graph_utils.py +++ b/scal3/graph_utils.py @@ -37,9 +37,7 @@ def addBoxHeightToColoredGraph(g): colorCount = max(colors) + 1 heightList = [1 for i in range(n)] for i, c in enumerate(colors): - adjColors = set() - for j in adjlist[i]: - adjColors.add(colors[j]) + adjColors = {colors[j] for j in adjlist[i]} for c_end in range(c + 1, colorCount + 1): if c_end in adjColors: heightList[i] = c_end - c diff --git a/scal3/os_utils.py b/scal3/os_utils.py index 6abeb7390..4a6a99bd4 100644 --- a/scal3/os_utils.py +++ b/scal3/os_utils.py @@ -57,7 +57,7 @@ def makeDir(direc): def getUsersData(): data = [] with open("/etc/passwd", encoding="utf-8") as fp: - for line in fp.readlines(): + for line in fp: parts = line.strip().split(":") if len(parts) < 7: continue diff --git a/scal3/ui_gtk/customize.py b/scal3/ui_gtk/customize.py index 8d8fb3bc1..14d849b3c 100644 --- a/scal3/ui_gtk/customize.py +++ b/scal3/ui_gtk/customize.py @@ -54,7 +54,7 @@ def __init__( self.enable = False self.objName = name self.desc = desc - self.moduleName = ".".join([pkg, name]) + self.moduleName = f"{pkg}.{name}" self.customizable = customizable self.optionsWidget = None self.items = [] diff --git a/scal3/ui_gtk/event/__init__.py b/scal3/ui_gtk/event/__init__.py index 746c717e0..28ceaaf11 100644 --- a/scal3/ui_gtk/event/__init__.py +++ b/scal3/ui_gtk/event/__init__.py @@ -19,13 +19,7 @@ def getWidgetClass(obj): if hasattr(cls, "WidgetClass"): return cls.WidgetClass - modulePath = ".".join( - [ - modPrefix, - cls.tname, - cls.name, - ], - ) + modulePath = f"{modPrefix}.{cls.tname}.{cls.name}" try: module = __import__(modulePath, fromlist=["WidgetClass"]) except Exception: @@ -55,13 +49,7 @@ def setActionFuncs(obj): cls = obj.__class__ try: module = __import__( - ".".join( - [ - modPrefix, - cls.tname, - cls.name, - ], - ), + f"{modPrefix}.{cls.tname}.{cls.name}", fromlist=["WidgetClass"], ) except Exception: diff --git a/scal3/ui_gtk/mainwin_items/monthCal.py b/scal3/ui_gtk/mainwin_items/monthCal.py index 2ed3d68b9..377a8fdc5 100644 --- a/scal3/ui_gtk/mainwin_items/monthCal.py +++ b/scal3/ui_gtk/mainwin_items/monthCal.py @@ -154,13 +154,7 @@ def __init__(self, win): gtk.DrawingArea.__init__(self) self.add_events(gdk.EventMask.ALL_EVENTS_MASK) self.initCal() - self.pagePath = ".".join( - [ - win.objName, - win.mainVBox.objName, - self.objName, - ], - ) + self.pagePath = f"{win.objName}.{win.mainVBox.objName}.{self.objName}" # ---------------------- # self.kTime = 0 # ---------------------- @@ -404,7 +398,7 @@ def drawWithContext(self, cr: cairo.Context, cursor: bool): iconsN = len(iconList) scaleFact = 1 / sqrt(iconsN) fromRight = 0 - for _index, icon in enumerate(iconList): + for icon in iconList: # if len(iconList) > 1 # FIXME try: pix = pixbufFromFile(icon, size=iconSizeMax) diff --git a/scal3/ui_gtk/starcal.py b/scal3/ui_gtk/starcal.py index 114a45f81..a112919bc 100755 --- a/scal3/ui_gtk/starcal.py +++ b/scal3/ui_gtk/starcal.py @@ -140,12 +140,7 @@ def createItems(self): if enable: try: module = __import__( - ".".join( - [ - itemsPkg, - name, - ], - ), + f"{itemsPkg}.{name}", fromlist=["CalObj"], ) CalObj = module.CalObj diff --git a/scal3/ui_gtk/statusBar.py b/scal3/ui_gtk/statusBar.py index 39a2f6248..7a2c9700e 100644 --- a/scal3/ui_gtk/statusBar.py +++ b/scal3/ui_gtk/statusBar.py @@ -54,7 +54,7 @@ def onConfigChange(self, *a, **kw): def onDateChange(self, *a, **kw): CustomizableCalObj.onDateChange(self, *a, **kw) labels = self.labelBox.get_children() - for _i, label in enumerate(labels): + for label in labels: text = ui.cell.format(ud.dateFormatBin, label.calType) if label.calType == calTypes.primary: text = f"{text}"