Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Python cleanups #10781
Conversation
fanquake
added the
Refactoring
label
Jul 10, 2017
jnewbery
reviewed
Jul 10, 2017
Looks good. utACK. One question inline and another general question:
In commit Use the variable name _ to show that we are intentionally ignoring a return value, why not just ignore the return value?
| @@ -293,7 +293,7 @@ def test_compactblock_construction(self, node, test_node, version, use_witness_a | ||
| # Store the raw block in our internal format. | ||
| block = FromHex(CBlock(), node.getblock("%02x" % block_hash, False)) | ||
| - [tx.calc_sha256() for tx in block.vtx] |
jnewbery
Jul 10, 2017
Member
I can't see how using tx is an issue. Does this cause a linter warning?
practicalswift
Jul 16, 2017
Contributor
Yes it does :-)
$ flake8 test/functional/p2p-compactblocks.py | grep redefine
test/functional/p2p-compactblocks.py:296:31: F812 list comprehension redefines 'tx' from line 276Should I remove the commit 263686d from this PR?
jnewbery
Jul 20, 2017
Member
actually, let's just swap this list comprehension for a for loop. We're using it for its side-effects, so a for loop is clearer.
| @@ -168,7 +168,7 @@ def test_bumpfee_with_descendant_fails(rbf_node, rbf_node_address, dest_address) | ||
| parent_id = spend_one_input(rbf_node, rbf_node_address) | ||
| tx = rbf_node.createrawtransaction([{"txid": parent_id, "vout": 0}], {dest_address: 0.00020000}) | ||
| tx = rbf_node.signrawtransaction(tx) | ||
| - txid = rbf_node.sendrawtransaction(tx["hex"]) | ||
| + _ = rbf_node.sendrawtransaction(tx["hex"]) |
jtimon
Jul 13, 2017
Member
what about something more clear like throwaway_txid or something of the sort?
|
fast review ACK |
practicalswift
added some commits
Jul 9, 2017
practicalswift
referenced
this pull request
Jul 19, 2017
Open
trivial: fix various pyflakes/vulture warnings #10881
|
Added two commits :-) |
| @@ -91,7 +91,7 @@ def handle(self): | ||
| self.conn.sendall(bytearray([0x01, 0x00])) | ||
| # Read connect request | ||
| - (ver,cmd,rsv,atyp) = recvall(self.conn, 4) | ||
| + (ver, cmd, _, atyp) = recvall(self.conn, 4) |
jnewbery
Jul 20, 2017
•
Member
no need for this to be a tuple. Just:
ver, cmd, _, atyp = recvall(self.conn, 4)
There are other examples in commit Use the variable name _ for unused return values. I won't comment on each of them.
| @@ -47,16 +47,16 @@ def run_test(self): | ||
| self.log.info("Ensure submitblock can in principle reorg to a competing chain") | ||
| self.nodes[0].generate(1) | ||
| assert_equal(self.nodes[0].getblockcount(), 1) | ||
| - (hashY, hashZ) = self.nodes[1].generate(2) | ||
| + (_, hashZ) = self.nodes[1].generate(2) |
jnewbery
Jul 20, 2017
Member
prefer:
hashZ = self.nodes[1].generate(2)[-1]
since it conveys the meaning better: "give me the hash of the last block generated".
same for the two examples below
| @@ -15,17 +15,7 @@ | ||
| import os | ||
| from binascii import unhexlify, hexlify | ||
| -STATE_ESTABLISHED = '01' |
| @@ -48,8 +48,6 @@ | ||
| COIN = 100000000 # 1 btc in satoshis | ||
| NODE_NETWORK = (1 << 0) | ||
| -NODE_GETUTXO = (1 << 1) |
practicalswift
Jul 20, 2017
•
Contributor
Good point! Updated but GitHub doesn't show the # NODE_GETUTXO = (1 << 1) below (in the comment view), so it appears as if it is not fixed :-)
| @@ -112,40 +112,16 @@ def set_secretbytes(self, secret): | ||
| ssl.BN_CTX_free(ctx) | ||
| return self.k | ||
| - def set_privkey(self, key): |
jnewbery
Jul 20, 2017
Member
I can imagine these methods potentially being useful at some point. I don't think there's any need to remove them.
| @@ -158,11 +158,6 @@ def __call__(self, *args, **argsn): | ||
| else: | ||
| return response['result'] | ||
| - def _batch(self, rpc_call_list): |
|
Mostly ACK, but a few comments. |
|
@jnewbery Thanks for reviewing! Good feedback - I've addressed all points raised. Would you mind re-reviewing? :-) |
|
Looks good. Just #10781 (comment) unaddressed (using a for loop instead of list comprehension for functions with side-effects) |
practicalswift
added some commits
Jul 20, 2017
|
@jnewbery Thanks! List comprehension now fixed as well. Looks good? :-) |
|
looks good. utACK db442ad |
practicalswift commentedJul 9, 2017
•
edited
Python cleanups:
stderrdoes not exist,sys.stderrdoesprint(...)instead of undefinedprintf(...)tx) in list comprehensionsys.exit(...)instead ofexit(...):exit(...)should not be used in programs