Skip to content

Commit b5df44f

Browse files
committed
add vulture hook
1 parent 140b1c2 commit b5df44f

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ repos:
88
hooks:
99
- id: absolufy-imports
1010
files: ^pandas/
11+
- repo: https://github.com/jendrikseipp/vulture
12+
rev: 'v2.3'
13+
hooks:
14+
- id: vulture
15+
entry: python scripts/run_vulture.py
16+
pass_filenames: true
17+
require_serial: false
1118
- repo: https://github.com/python/black
1219
rev: 21.12b0
1320
hooks:

pandas/tests/frame/test_constructors.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,8 +1285,7 @@ def test_constructor_empty_list(self):
12851285

12861286
# Empty generator: list(empty_gen()) == []
12871287
def empty_gen():
1288-
return
1289-
yield
1288+
yield from ()
12901289

12911290
df = DataFrame(empty_gen(), columns=["A", "B"])
12921291
tm.assert_frame_equal(df, expected)

pandas/tests/io/test_common.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,6 @@ def test_encoding_errors(encoding_errors, format):
556556

557557
if format == "csv":
558558
return
559-
content = bad_encoding + b"\n" + bad_encoding
560-
reader = pd.read_csv
561559
else:
562560
content = (
563561
b'{"'

scripts/run_vulture.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Run Vulture, but filter out "unused variable" errors - only find unreachable code.
3+
4+
Might be able to get rid of this if in Vulture they let us filter out errors by
5+
their codes, see
6+
https://github.com/jendrikseipp/vulture/issues/269#issuecomment-1004048279.
7+
"""
8+
9+
import argparse
10+
import subprocess
11+
import sys
12+
13+
if __name__ == "__main__":
14+
parser = argparse.ArgumentParser()
15+
parser.add_argument("files", nargs="*")
16+
args = parser.parse_args()
17+
18+
output = subprocess.run(
19+
["vulture", "--min-confidence", "100", *args.files],
20+
text=True,
21+
capture_output=True,
22+
)
23+
stdout = "".join(
24+
[
25+
line
26+
for line in output.stdout.splitlines(keepends=True)
27+
if "unused variable" not in line
28+
]
29+
)
30+
sys.stdout.write(stdout)
31+
ret = bool(stdout)
32+
sys.exit(ret)

0 commit comments

Comments
 (0)