From de4937b82c31efe6c62c2c8f67f3bfb8aab85c32 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 7 Aug 2026 09:37:46 +0000 Subject: [PATCH] ruff C402 (unnecessary generator (rewrite as dict comprehension)) --- mmgen/obj.py | 2 +- mmgen/opts.py | 6 +++--- mmgen/proto/btc/rpc/local.py | 2 +- mmgen/proto/eth/rlp/sedes/serializable.py | 6 +----- mmgen/tw/store.py | 2 +- mmgen/util.py | 2 +- mmgen/xmrwallet/file/__init__.py | 2 +- pyproject.toml | 1 - 8 files changed, 9 insertions(+), 14 deletions(-) diff --git a/mmgen/obj.py b/mmgen/obj.py index 187bc969..be4bbb68 100755 --- a/mmgen/obj.py +++ b/mmgen/obj.py @@ -213,7 +213,7 @@ class MMGenListItem(MMGenObject): return object.__setattr__(self, name, value) def _asdict(self): - return dict((k, v) for k, v in self.__dict__.items() if k in self.valid_attrs) + return {k: v for k, v in self.__dict__.items() if k in self.valid_attrs} class MMGenRange(tuple, InitErrors, MMGenObject): diff --git a/mmgen/opts.py b/mmgen/opts.py index e244f516..7ca62a91 100755 --- a/mmgen/opts.py +++ b/mmgen/opts.py @@ -29,10 +29,10 @@ def negated_opts(opts, data={}): if data: return data else: - data.update(dict( - ((k[3:] if k.startswith('no-') else f'no-{k}'), v) + data.update({ + (k[3:] if k.startswith('no-') else f'no-{k}'): v for k, v in opts.items() - if len(k) > 1 and not v.has_parm)) + if len(k) > 1 and not v.has_parm}) return data def get_opt_by_substring(opt, opts): diff --git a/mmgen/proto/btc/rpc/local.py b/mmgen/proto/btc/rpc/local.py index c8227881..b11ec9fd 100755 --- a/mmgen/proto/btc/rpc/local.py +++ b/mmgen/proto/btc/rpc/local.py @@ -364,7 +364,7 @@ class BitcoinRPCClient(RPCClient, metaclass=AsyncInit): self.cfg, fn, desc='daemon config file', silent=not self.cfg.verbose) except: self.cfg._util.vmsg(f'Warning: {fn!r} does not exist or is unreadable') - return dict((k, None) for k in req_keys) + return {k: None for k in req_keys} def gen(): for key in req_keys: diff --git a/mmgen/proto/eth/rlp/sedes/serializable.py b/mmgen/proto/eth/rlp/sedes/serializable.py index de9fe62f..0e20041d 100644 --- a/mmgen/proto/eth/rlp/sedes/serializable.py +++ b/mmgen/proto/eth/rlp/sedes/serializable.py @@ -204,11 +204,7 @@ class BaseSerializable(collections.abc.Sequence): _cached_rlp = None def as_dict(self): - return dict( - (field, value) - for field, value - in zip(self._meta.field_names, self) - ) + return {field: value for field, value in zip(self._meta.field_names, self)} def __iter__(self): for attr in self._meta.field_attrs: diff --git a/mmgen/tw/store.py b/mmgen/tw/store.py index ed5e3847..8d7eb098 100755 --- a/mmgen/tw/store.py +++ b/mmgen/tw/store.py @@ -191,7 +191,7 @@ class TwCtlWithStore(TwCtl, metaclass=AsyncInit): @property def mmid_ordered_dict(self): - return dict((x['mmid'], {'addr': x['addr'], 'comment': x['comment']}) for x in self.sorted_list) + return {x['mmid']: {'addr': x['addr'], 'comment': x['comment']} for x in self.sorted_list} async def get_label_addr_pairs(self): return [label_addr_pair( diff --git a/mmgen/util.py b/mmgen/util.py index d13c3523..b89876c2 100755 --- a/mmgen/util.py +++ b/mmgen/util.py @@ -385,7 +385,7 @@ def is_utf8(s): return True def remove_whitespace(s, *, ws='\t\r\n '): - return s.translate(dict((ord(e), None) for e in ws)) + return s.translate({ord(e): None for e in ws}) def strip_comment(line): return re.sub('#.*', '', line).rstrip() diff --git a/mmgen/xmrwallet/file/__init__.py b/mmgen/xmrwallet/file/__init__.py index 8ad61085..785ec025 100755 --- a/mmgen/xmrwallet/file/__init__.py +++ b/mmgen/xmrwallet/file/__init__.py @@ -23,7 +23,7 @@ class MoneroMMGenFile: def make_chksum(self, *, keys=None): res = json.dumps( - dict((k, v) for k, v in self.data._asdict().items() if (not keys or k in keys)), + {k: v for k, v in self.data._asdict().items() if (not keys or k in keys)}, cls = json_encoder) return make_chksum_N(res, rounds=1, nchars=self.chksum_nchars, upper=False) diff --git a/pyproject.toml b/pyproject.toml index 4dc6d45b..0853a3bc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,6 @@ ignore = [ "B018", # Found useless expression. Either assign it to a variable or remove it. "B026", # Star-arg unpacking after a keyword argument is strongly discouraged "BLE001", # Do not catch blind exception: `Exception` - "C402", # Unnecessary generator (rewrite as a dict comprehension) "C409", # Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal) "C410", # Unnecessary list literal passed to `list()` (remove the outer call to `list()`) "C414", # Unnecessary `list()` call within `set()`