From f311f468407848849b7d746f7b02bb59cbcb95aa Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 7 Aug 2026 09:37:46 +0000 Subject: [PATCH] ruff B010 (`setattr` with constant attribute value) --- mmgen/devinit.py | 2 +- mmgen/util.py | 2 +- pyproject.toml | 1 - test/tooltest2.py | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/mmgen/devinit.py b/mmgen/devinit.py index c027896d..a83343d3 100755 --- a/mmgen/devinit.py +++ b/mmgen/devinit.py @@ -68,6 +68,6 @@ def init_dev(): import builtins # MMGenObject is added to the namespace by objmethods.py, so we must name the builtin differently # to avoid inadvertently adding MMGenObject to the global namespace here: - setattr(builtins, 'MMGenObjectDevTools', MMGenObjectDevTools) + builtins.MMGenObjectDevTools = MMGenObjectDevTools for funcname, func in devtools_funcs.items(): setattr(builtins, funcname, func) diff --git a/mmgen/util.py b/mmgen/util.py index 0cbc1c18..d13c3523 100755 --- a/mmgen/util.py +++ b/mmgen/util.py @@ -411,7 +411,7 @@ class oneshot_warning: msg(getattr(color, wcls.color)('WARNING: ' + wcls.message.format(*fmt_args))) if not hasattr(wcls, 'data'): - setattr(wcls, 'data', []) + wcls.data = [] data = wcls.data condition = (div in data) if reverse else (not div in data) diff --git a/pyproject.toml b/pyproject.toml index 37ebc28f..86a4a884 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,6 @@ indent-style = "tab" ignore = [ "ASYNC221", # blocking method in async function (mmgen/rpc/backends/curl.py) "B006", # Do not use mutable data structures for argument defaults - "B010", # Do not call `setattr` with a constant attribute value. It is not any safer than normal property access. "B018", # Found useless expression. Either assign it to a variable or remove it. "B023", # Function definition does not bind loop variable `confs` "B026", # Star-arg unpacking after a keyword argument is strongly discouraged diff --git a/test/tooltest2.py b/test/tooltest2.py index 6354d555..044fca1a 100755 --- a/test/tooltest2.py +++ b/test/tooltest2.py @@ -339,7 +339,7 @@ if cfg.list_tests: Msg('Available tests:') for modname, cmdlist in main_tool.mods.items(): cls = importlib.import_module(f'mmgen.tool.{modname}').tool_cmd - Msg(f' {modname:10} - {docstring_head(cls)}') + Msg(f' {modname:6} - {docstring_head(cls)}') sys.exit(0) if cfg.list_tested_cmds: