ruff FURB157 (verbose expression in Decimal constructor)
This commit is contained in:
parent
223c971175
commit
18e82cca91
7 changed files with 9 additions and 10 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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).
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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')},
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue