Skip to content

Commit

Permalink
Split into two functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jendrikseipp committed Nov 24, 2024
1 parent c1e474f commit 980088f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
24 changes: 12 additions & 12 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ def check(items_or_names, expected_names):
assert items_or_names == set(expected_names)


def check_unreachable(v, lineno, size, name, multiple=False):
# Match by lineno, if we allow multiple unreachables, otherwise
# the first unreachable item is taken.
if multiple:
item = next(
item for item in v.unreachable_code if item.first_lineno == lineno
)
else:
assert len(v.unreachable_code) == 1
item = v.unreachable_code[0]
assert item.first_lineno == lineno

def check_unreachable(v, lineno, size, name):
assert len(v.unreachable_code) == 1
item = v.unreachable_code[0]
assert item.first_lineno == lineno
assert item.size == size
assert item.name == name


def check_multiple_unreachable(v, checks):
assert len(v.unreachable_code) == len(checks)
for item, (lineno, size, name) in zip(v.unreachable_code, checks):
assert item.first_lineno == lineno
assert item.size == size
assert item.name == name


@pytest.fixture
def v():
return core.Vulture(verbose=True)
8 changes: 3 additions & 5 deletions tests/test_reachability.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import check_unreachable
from . import check_multiple_unreachable, check_unreachable
from . import v

assert v # Silence pyflakes
Expand Down Expand Up @@ -479,8 +479,7 @@ def foo(a):
print(":-(")
"""
)
check_unreachable(v, 2, 2, "if", multiple=True)
check_unreachable(v, 4, 1, "if", multiple=True)
check_multiple_unreachable(v, [(2, 2, "if"), (4, 1, "if")])


def test_if_true_return_else(v):
Expand All @@ -494,8 +493,7 @@ def foo(a):
print(":-(")
"""
)
check_unreachable(v, 5, 1, "else", multiple=True)
check_unreachable(v, 6, 1, "if", multiple=True)
check_multiple_unreachable(v, [(5, 1, "else"), (6, 1, "if")])


def test_if_some_branches_return(v):
Expand Down
2 changes: 1 addition & 1 deletion vulture/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from vulture import noqa
from vulture import utils
from vulture.config import InputError, make_config
from vulture.utils import ExitCode
from vulture.reachability import Reachability
from vulture.utils import ExitCode


DEFAULT_CONFIDENCE = 60
Expand Down
1 change: 1 addition & 0 deletions vulture/reachability.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def __init__(self, report):
self._no_fall_through_nodes = set()

def visit(self, node):
"""When called, all children of this node have already been visited."""
if isinstance(node, (ast.Break, ast.Continue, ast.Return, ast.Raise)):
self._mark_as_no_fall_through(node)
elif isinstance(
Expand Down

0 comments on commit 980088f

Please sign in to comment.