Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 1d2a0cb

Browse files
committed
PEP8
1 parent 4d68dc5 commit 1d2a0cb

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

ethereum/abi.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ def decint(n, signed=False):
255255
n = utils.to_string(n)
256256

257257
if is_numeric(n):
258-
min, max = (-TT255,TT255-1) if signed else (0,TT256-1)
259-
if n > max or n < min:
258+
min_, max_ = (-TT255, TT255 - 1) if signed else (0, TT256 - 1)
259+
if n > max_ or n < min_:
260260
raise EncodingError("Number out of range: %r" % n)
261261
return n
262262
elif is_string(n):
@@ -274,6 +274,7 @@ def decint(n, signed=False):
274274
else:
275275
raise EncodingError("Cannot encode integer: %r" % n)
276276

277+
277278
# Encodes a base datum
278279
def encode_single(typ, arg):
279280
base, sub, _ = typ
@@ -282,7 +283,7 @@ def encode_single(typ, arg):
282283
sub = int(sub)
283284
i = decint(arg, False)
284285

285-
if not 0 <= i < 2**sub:
286+
if not 0 <= i < 2 ** sub:
286287
raise ValueOutOfBounds(repr(arg))
287288
return zpad(encode_int(i), 32)
288289
# bool: int<sz>
@@ -293,22 +294,22 @@ def encode_single(typ, arg):
293294
elif base == 'int':
294295
sub = int(sub)
295296
i = decint(arg, True)
296-
if not -2**(sub - 1) <= i < 2**(sub - 1):
297+
if not -2 ** (sub - 1) <= i < 2 ** (sub - 1):
297298
raise ValueOutOfBounds(repr(arg))
298-
return zpad(encode_int(i % 2**sub), 32)
299+
return zpad(encode_int(i % 2 ** sub), 32)
299300
# Unsigned reals: ureal<high>x<low>
300301
elif base == 'ureal':
301302
high, low = [int(x) for x in sub.split('x')]
302-
if not 0 <= arg < 2**high:
303+
if not 0 <= arg < 2 ** high:
303304
raise ValueOutOfBounds(repr(arg))
304-
return zpad(encode_int(int(arg * 2**low)), 32)
305+
return zpad(encode_int(int(arg * 2 ** low)), 32)
305306
# Signed reals: real<high>x<low>
306307
elif base == 'real':
307308
high, low = [int(x) for x in sub.split('x')]
308-
if not -2**(high - 1) <= arg < 2**(high - 1):
309+
if not -2 ** (high - 1) <= arg < 2 ** (high - 1):
309310
raise ValueOutOfBounds(repr(arg))
310-
i = int(arg * 2**low)
311-
return zpad(encode_int(i % 2**(high+low)), 32)
311+
i = int(arg * 2 ** low)
312+
return zpad(encode_int(i % 2 ** (high + low)), 32)
312313
# Strings
313314
elif base == 'string' or base == 'bytes':
314315
if not is_string(arg):
@@ -480,7 +481,7 @@ def decode_single(typ, data):
480481
if base == 'address':
481482
return encode_hex(data[12:])
482483
elif base == 'hash':
483-
return data[32-int(sub):]
484+
return data[32 - int(sub):]
484485
elif base == 'string' or base == 'bytes':
485486
if len(sub):
486487
return data[:int(sub)]
@@ -491,15 +492,15 @@ def decode_single(typ, data):
491492
return big_endian_to_int(data)
492493
elif base == 'int':
493494
o = big_endian_to_int(data)
494-
return (o - 2**int(sub)) if o >= 2**(int(sub) - 1) else o
495+
return (o - 2 ** int(sub)) if o >= 2 ** (int(sub) - 1) else o
495496
elif base == 'ureal':
496497
high, low = [int(x) for x in sub.split('x')]
497-
return big_endian_to_int(data) * 1.0 // 2**low
498+
return big_endian_to_int(data) * 1.0 // 2 ** low
498499
elif base == 'real':
499500
high, low = [int(x) for x in sub.split('x')]
500501
o = big_endian_to_int(data)
501-
i = (o - 2**(high+low)) if o >= 2**(high+low-1) else o
502-
return (i * 1.0 // 2**low)
502+
i = (o - 2 ** (high + low)) if o >= 2 ** (high + low - 1) else o
503+
return (i * 1.0 // 2 ** low)
503504
elif base == 'bool':
504505
return bool(int(encode_hex(data), 16))
505506

0 commit comments

Comments
 (0)