Skip to content

Commit d26d15c

Browse files
author
MarcoFalke
committed
Merge #14365: tests: Add Python dead code linter (vulture) to Travis
c82190c tests: Add Python dead code linter (vulture) (practicalswift) 590a57f tests: Remove unused testing code (practicalswift) Pull request description: Add Python dead code linter (`vulture`) to Travis. Rationale for allowing dead code only after explicit opt-in (via `--ignore-names`): * Less is more :-) * Unused code is by definition "untested" * Unused code can be an indication of bugs/logical errors. By making the contributor aware of newly introduced unused code it gives him/her an opportunity to investigate if the unused code they introduce is malignant or benign :-) * Unused code is hard to spot for humans and is thus often missed during manual review * [YAGNI](https://en.wikipedia.org/wiki/You_aren%27t_gonna_need_it) Based on #14312 to make linter job pass. Tree-SHA512: 4c581df7c34986e226e4ade479e0d3c549daf38f4a4dc4564b25564d63e773a1830ba55d1289c771b1fa325483e8855b82b56e61859fe8e4b7dfa54034b093b6
2 parents e8d490f + c82190c commit d26d15c

File tree

8 files changed

+26
-14
lines changed

8 files changed

+26
-14
lines changed

.travis/lint_04_install.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export LC_ALL=C
88

99
travis_retry pip install codespell==1.13.0
1010
travis_retry pip install flake8==3.5.0
11+
travis_retry pip install vulture==0.29

test/functional/feature_cltv.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
# Reject codes that we might receive in this test
2727
REJECT_INVALID = 16
28-
REJECT_OBSOLETE = 17
2928
REJECT_NONSTANDARD = 64
3029

3130
def cltv_invalidate(tx):

test/functional/feature_dersig.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
# Reject codes that we might receive in this test
2424
REJECT_INVALID = 16
25-
REJECT_OBSOLETE = 17
2625
REJECT_NONSTANDARD = 64
2726

2827
# A canonical signature consists of:

test/functional/test_framework/messages.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
MY_SUBVERSION = b"/python-mininode-tester:0.0.3/"
3636
MY_RELAY = 1 # from version 70001 onwards, fRelay should be appended to version messages (BIP37)
3737

38-
MAX_INV_SZ = 50000
3938
MAX_LOCATOR_SZ = 101
4039
MAX_BLOCK_BASE_SIZE = 1000000
4140

@@ -58,9 +57,6 @@
5857
def sha256(s):
5958
return hashlib.new('sha256', s).digest()
6059

61-
def ripemd160(s):
62-
return hashlib.new('ripemd160', s).digest()
63-
6460
def hash256(s):
6561
return sha256(sha256(s))
6662

@@ -887,13 +883,12 @@ def __repr__(self):
887883

888884

889885
class CPartialMerkleTree:
890-
__slots__ = ("fBad", "nTransactions", "vBits", "vHash")
886+
__slots__ = ("nTransactions", "vBits", "vHash")
891887

892888
def __init__(self):
893889
self.nTransactions = 0
894890
self.vHash = []
895891
self.vBits = []
896-
self.fBad = False
897892

898893
def deserialize(self, f):
899894
self.nTransactions = struct.unpack("<i", f.read(4))[0]

test/functional/test_framework/mininode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def on_ping(self, message):
349349
self.send_message(msg_pong(message.nonce))
350350

351351
def on_verack(self, message):
352-
self.verack_received = True
352+
pass
353353

354354
def on_version(self, message):
355355
assert message.nVersion >= MIN_VERSION_SUPPORTED, "Version {} received. Test framework only supports versions greater than {}".format(message.nVersion, MIN_VERSION_SUPPORTED)

test/functional/test_framework/socks5.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ def __repr__(self):
5454
return 'Socks5Command(%s,%s,%s,%s,%s,%s)' % (self.cmd, self.atyp, self.addr, self.port, self.username, self.password)
5555

5656
class Socks5Connection():
57-
def __init__(self, serv, conn, peer):
57+
def __init__(self, serv, conn):
5858
self.serv = serv
5959
self.conn = conn
60-
self.peer = peer
6160

6261
def handle(self):
6362
"""Handle socks5 request according to RFC192."""
@@ -137,9 +136,9 @@ def __init__(self, conf):
137136

138137
def run(self):
139138
while self.running:
140-
(sockconn, peer) = self.s.accept()
139+
(sockconn, _) = self.s.accept()
141140
if self.running:
142-
conn = Socks5Connection(self, sockconn, peer)
141+
conn = Socks5Connection(self, sockconn)
143142
thread = threading.Thread(None, conn.handle)
144143
thread.daemon = True
145144
thread.start()

test/functional/test_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ def _get_uncovered_rpc_commands(self):
635635
with open(coverage_ref_filename, 'r', encoding="utf8") as coverage_ref_file:
636636
all_cmds.update([line.strip() for line in coverage_ref_file.readlines()])
637637

638-
for root, dirs, files in os.walk(self.dir):
638+
for root, _, files in os.walk(self.dir):
639639
for filename in files:
640640
if filename.startswith(coverage_file_prefix):
641641
coverage_filenames.add(os.path.join(root, filename))

test/lint/lint-python-dead-code.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2018 The Bitcoin Core developers
4+
# Distributed under the MIT software license, see the accompanying
5+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
6+
#
7+
# Find dead Python code.
8+
9+
export LC_ALL=C
10+
11+
if ! command -v vulture > /dev/null; then
12+
echo "Skipping Python dead code linting since vulture is not installed. Install by running \"pip3 install vulture\""
13+
exit 0
14+
fi
15+
16+
vulture \
17+
--min-confidence 60 \
18+
--ignore-names "argtypes,connection_lost,connection_made,converter,data_received,daemon,errcheck,get_ecdh_key,get_privkey,is_compressed,is_fullyvalid,msg_generic,on_*,optionxform,restype,set_privkey" \
19+
$(git ls-files -- "*.py" ":(exclude)contrib/")

0 commit comments

Comments
 (0)