Skip to content

Commit

Permalink
test: use zero-argument super() shortcut (Python 3.0+)
Browse files Browse the repository at this point in the history
as defined in PEP 3135:

"The new syntax:

    super()

is equivalent to:

    super(__class__, <firstarg>)

where __class__ is the class that the method was defined in, and <firstarg> is
the first parameter of the method (normally self for instance methods, and cls
for class methods)."
  • Loading branch information
theStack committed Apr 25, 2020
1 parent 5f19155 commit 0956e46
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions test/functional/test_framework/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,16 +603,16 @@ class CBlock(CBlockHeader):
__slots__ = ("vtx",)

def __init__(self, header=None):
super(CBlock, self).__init__(header)
super().__init__(header)
self.vtx = []

def deserialize(self, f):
super(CBlock, self).deserialize(f)
super().deserialize(f)
self.vtx = deser_vector(f, CTransaction)

def serialize(self, with_witness=True):
r = b""
r += super(CBlock, self).serialize()
r += super().serialize()
if with_witness:
r += ser_vector(self.vtx, "serialize_with_witness")
else:
Expand Down Expand Up @@ -752,7 +752,7 @@ def __repr__(self):
class P2PHeaderAndShortWitnessIDs(P2PHeaderAndShortIDs):
__slots__ = ()
def serialize(self):
return super(P2PHeaderAndShortWitnessIDs, self).serialize(with_witness=True)
return super().serialize(with_witness=True)

# Calculate the BIP 152-compact blocks shortid for a given transaction hash
def calculate_shortid(k0, k1, tx_hash):
Expand Down
8 changes: 4 additions & 4 deletions test/functional/test_framework/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __new__(cls, n):
return _opcode_instances[n]
except IndexError:
assert len(_opcode_instances) == n
_opcode_instances.append(super(CScriptOp, cls).__new__(cls, n))
_opcode_instances.append(super().__new__(cls, n))
return _opcode_instances[n]

# Populate opcode instance table
Expand Down Expand Up @@ -372,7 +372,7 @@ class CScriptTruncatedPushDataError(CScriptInvalidError):
"""Invalid pushdata due to truncation"""
def __init__(self, msg, data):
self.data = data
super(CScriptTruncatedPushDataError, self).__init__(msg)
super().__init__(msg)


# This is used, eg, for blockchain heights in coinbase scripts (bip34)
Expand Down Expand Up @@ -458,14 +458,14 @@ def join(self, iterable):

def __new__(cls, value=b''):
if isinstance(value, bytes) or isinstance(value, bytearray):
return super(CScript, cls).__new__(cls, value)
return super().__new__(cls, value)
else:
def coerce_iterable(iterable):
for instance in iterable:
yield cls.__coerce_instance(instance)
# Annoyingly on both python2 and python3 bytes.join() always
# returns a bytes instance even when subclassed.
return super(CScript, cls).__new__(cls, b''.join(coerce_iterable(value)))
return super().__new__(cls, b''.join(coerce_iterable(value)))

def raw_iter(self):
"""Raw iteration
Expand Down
2 changes: 1 addition & 1 deletion test/functional/wallet_txn_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def add_options(self, parser):

def setup_network(self):
# Start with split network:
super(TxnMallTest, self).setup_network()
super().setup_network()
disconnect_nodes(self.nodes[1], 2)
disconnect_nodes(self.nodes[2], 1)

Expand Down

0 comments on commit 0956e46

Please sign in to comment.