0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-12 11:19:08 -05:00

test: use zero-argument super() shortcut (Python 3.0+)

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)."
This commit is contained in:
Sebastian Falbesoner 2020-04-10 17:39:36 +02:00
parent 5f19155e5b
commit 0956e46bff
3 changed files with 9 additions and 9 deletions

View file

@ -603,16 +603,16 @@ class CBlock(CBlockHeader):
__slots__ = ("vtx",) __slots__ = ("vtx",)
def __init__(self, header=None): def __init__(self, header=None):
super(CBlock, self).__init__(header) super().__init__(header)
self.vtx = [] self.vtx = []
def deserialize(self, f): def deserialize(self, f):
super(CBlock, self).deserialize(f) super().deserialize(f)
self.vtx = deser_vector(f, CTransaction) self.vtx = deser_vector(f, CTransaction)
def serialize(self, with_witness=True): def serialize(self, with_witness=True):
r = b"" r = b""
r += super(CBlock, self).serialize() r += super().serialize()
if with_witness: if with_witness:
r += ser_vector(self.vtx, "serialize_with_witness") r += ser_vector(self.vtx, "serialize_with_witness")
else: else:
@ -752,7 +752,7 @@ class P2PHeaderAndShortIDs:
class P2PHeaderAndShortWitnessIDs(P2PHeaderAndShortIDs): class P2PHeaderAndShortWitnessIDs(P2PHeaderAndShortIDs):
__slots__ = () __slots__ = ()
def serialize(self): 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 # Calculate the BIP 152-compact blocks shortid for a given transaction hash
def calculate_shortid(k0, k1, tx_hash): def calculate_shortid(k0, k1, tx_hash):

View file

@ -97,7 +97,7 @@ class CScriptOp(int):
return _opcode_instances[n] return _opcode_instances[n]
except IndexError: except IndexError:
assert len(_opcode_instances) == n 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] return _opcode_instances[n]
# Populate opcode instance table # Populate opcode instance table
@ -372,7 +372,7 @@ class CScriptTruncatedPushDataError(CScriptInvalidError):
"""Invalid pushdata due to truncation""" """Invalid pushdata due to truncation"""
def __init__(self, msg, data): def __init__(self, msg, data):
self.data = data self.data = data
super(CScriptTruncatedPushDataError, self).__init__(msg) super().__init__(msg)
# This is used, eg, for blockchain heights in coinbase scripts (bip34) # This is used, eg, for blockchain heights in coinbase scripts (bip34)
@ -458,14 +458,14 @@ class CScript(bytes):
def __new__(cls, value=b''): def __new__(cls, value=b''):
if isinstance(value, bytes) or isinstance(value, bytearray): if isinstance(value, bytes) or isinstance(value, bytearray):
return super(CScript, cls).__new__(cls, value) return super().__new__(cls, value)
else: else:
def coerce_iterable(iterable): def coerce_iterable(iterable):
for instance in iterable: for instance in iterable:
yield cls.__coerce_instance(instance) yield cls.__coerce_instance(instance)
# Annoyingly on both python2 and python3 bytes.join() always # Annoyingly on both python2 and python3 bytes.join() always
# returns a bytes instance even when subclassed. # 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): def raw_iter(self):
"""Raw iteration """Raw iteration

View file

@ -29,7 +29,7 @@ class TxnMallTest(BitcoinTestFramework):
def setup_network(self): def setup_network(self):
# Start with split network: # Start with split network:
super(TxnMallTest, self).setup_network() super().setup_network()
disconnect_nodes(self.nodes[1], 2) disconnect_nodes(self.nodes[1], 2)
disconnect_nodes(self.nodes[2], 1) disconnect_nodes(self.nodes[2], 1)