From 18e82cca9160999025c454cb574a3f001b701387 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 7 Aug 2026 09:37:47 +0000 Subject: [PATCH] ruff FURB157 (verbose expression in `Decimal` constructor) --- mmgen/amt.py | 2 +- mmgen/proto/eth/contract.py | 4 ++-- mmgen/proto/rune/tx/protobuf.py | 4 ++-- pyproject.toml | 1 - test/modtest_d/lockable.py | 4 ++-- test/objtest_d/btc_mainnet.py | 2 +- test/objtest_d/eth_mainnet.py | 2 +- 7 files changed, 9 insertions(+), 10 deletions(-) diff --git a/mmgen/amt.py b/mmgen/amt.py index b4b9899d..6a120a25 100755 --- a/mmgen/amt.py +++ b/mmgen/amt.py @@ -52,7 +52,7 @@ class CoinAmt(Decimal, Hilite, InitErrors): # abstract class me = Decimal.__new__(cls, num * getattr(cls, from_unit)) elif from_decimal: assert isinstance(num, Decimal), f'number must be of type Decimal, not {type(num).__name__})' - me = Decimal.__new__(cls, num.quantize(Decimal('10') ** -cls.max_prec)) + me = Decimal.__new__(cls, num.quantize(Decimal(10) ** -cls.max_prec)) else: assert isinstance(num, str), f'non-string passed to {cls.__name__} initializer' me = Decimal.__new__(cls, num) diff --git a/mmgen/proto/eth/contract.py b/mmgen/proto/eth/contract.py index 5b812b99..dae0f36b 100755 --- a/mmgen/proto/eth/contract.py +++ b/mmgen/proto/eth/contract.py @@ -134,7 +134,7 @@ class Token(Contract): if decimals: assert isinstance(decimals, int), f'decimals param must be int instance, not {type(decimals)}' self.decimals = decimals - self.base_unit = Decimal('10') ** -self.decimals + self.base_unit = Decimal(10) ** -self.decimals async def get_balance(self, acct_addr, block='latest'): return self.proto.coin_amt( @@ -200,7 +200,7 @@ class ResolvedToken(Token, metaclass=AsyncInit): self.decimals = await self.get_decimals() if not self.decimals: die('TokenNotInBlockchain', f'Token {addr!r} not in blockchain') - self.base_unit = Decimal('10') ** -self.decimals + self.base_unit = Decimal(10) ** -self.decimals # Tokens: First approve router to spend tokens from user: asset.approve(router,amount). # Then call router.depositWithExpiry(inbound_address, asset, amount, memo, expiry). diff --git a/mmgen/proto/rune/tx/protobuf.py b/mmgen/proto/rune/tx/protobuf.py index 939ecc0c..363ce0d4 100755 --- a/mmgen/proto/rune/tx/protobuf.py +++ b/mmgen/proto/rune/tx/protobuf.py @@ -151,10 +151,10 @@ class RuneTx(Tx): signatures: Annotated[List[bytes], Field(3)] def amt_to_base_unit(amt, *, decimals): - return int(Decimal(amt) * (Decimal('10') ** decimals)) + return int(Decimal(amt) * (Decimal(10) ** decimals)) def base_unit_to_amt(n, *, decimals): - return n * Decimal('10') ** -decimals + return n * Decimal(10) ** -decimals def tx_info(tx, proto): b = tx.body.messages[0].body diff --git a/pyproject.toml b/pyproject.toml index 41f3daea..5329eb6b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,6 @@ ignore = [ "B026", # Star-arg unpacking after a keyword argument is strongly discouraged "BLE001", # Do not catch blind exception: `Exception` "E722", # bare except - "FURB157", # Verbose expression in `Decimal` constructor "FURB163", # Prefer `math.log2(state.lanew)` over `math.log` with a redundant base "FURB166", # Use of `int` with explicit `base=16` after removing prefix "FURB192", # Prefer `max` over `sorted()` to compute the maximum value in a sequence diff --git a/test/modtest_d/lockable.py b/test/modtest_d/lockable.py index 1148c1cf..538f9bfe 100755 --- a/test/modtest_d/lockable.py +++ b/test/modtest_d/lockable.py @@ -78,7 +78,7 @@ class unit_tests: # are these considered set? lc.alpha = 0 # yes lc.beta = False # yes - lc.gamma = Decimal('0') # yes + lc.gamma = Decimal(0) # yes lc.delta = 0.0 # yes lc.epsilon = [] # no @@ -98,7 +98,7 @@ class unit_tests: def bad4(): lc.x = 1 def bad5(): lc.alpha = 0 def bad6(): lc.beta = False - def bad7(): lc.gamma = Decimal('0') + def bad7(): lc.gamma = Decimal(0) def bad8(): lc.delta = float(0) def bad9(): lc.epsilon = [0] diff --git a/test/objtest_d/btc_mainnet.py b/test/objtest_d/btc_mainnet.py index d590898a..7add6e50 100755 --- a/test/objtest_d/btc_mainnet.py +++ b/test/objtest_d/btc_mainnet.py @@ -113,7 +113,7 @@ tests = { # rounding {'num': Decimal('1.23456789623456789'), 'from_decimal': True, 'ret': Decimal('1.23456790')}, {'num': Decimal('1.234'), 'from_decimal': True, 'ret': Decimal('1.234')}, - {'num': Decimal('0.0'), 'from_decimal': True, 'ret': Decimal('0')}, + {'num': Decimal('0.0'), 'from_decimal': True, 'ret': Decimal(0)}, # emulate network fee estimation: # BTC/kB fee_adjust tx size { 'num': Decimal('0.00053249') * Decimal('0.9') * 109 / 1024 , # ≈53 sat/byte diff --git a/test/objtest_d/eth_mainnet.py b/test/objtest_d/eth_mainnet.py index f0d295d2..432375b4 100755 --- a/test/objtest_d/eth_mainnet.py +++ b/test/objtest_d/eth_mainnet.py @@ -40,7 +40,7 @@ tests = { 'from_decimal': True, 'ret': Decimal('1.123456789123456789')}, {'num': Decimal('1.234'), 'from_decimal': True, 'ret': Decimal('1.234')}, - {'num': Decimal('0.0'), 'from_decimal': True, 'ret': Decimal('0')}, + {'num': Decimal('0.0'), 'from_decimal': True, 'ret': Decimal(0)}, {'num': 1234, 'from_unit': 'wei', 'ret': Decimal('0.000000000000001234')}, {'num': 1234, 'from_unit': 'Mwei', 'ret': Decimal('0.000000001234')}, )