-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the requirements to be a recursive call stricter (only top-level…
… recursion). Also add some tests.
- Loading branch information
1 parent
0a6bd9a
commit 682241a
Showing
3 changed files
with
114 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from . import check, v | ||
|
||
assert v # Silence pyflakes. | ||
|
||
|
||
def test_recursion1(v): | ||
v.scan( | ||
"""\ | ||
def Rec(): | ||
Rec() | ||
""" | ||
) | ||
check(v.defined_funcs, ["Rec"]) | ||
check(v.unused_funcs, ["Rec"]) | ||
|
||
|
||
def test_recursion2(v): | ||
v.scan( | ||
"""\ | ||
def Rec(): | ||
Rec() | ||
class MyClass: | ||
def __init__(self): | ||
pass | ||
def Rec(): | ||
Rec() # calls global Rec() | ||
def main(): | ||
main() | ||
""" | ||
) | ||
check(v.defined_funcs, ["Rec", "Rec", "main"]) | ||
check(v.unused_funcs, ["main"]) | ||
|
||
|
||
def test_recursion3(v): | ||
v.scan( | ||
"""\ | ||
class MyClass: | ||
def __init__(self): | ||
pass | ||
def Rec(): | ||
pass | ||
def Rec(): | ||
MyClass.Rec() | ||
""" | ||
) | ||
check(v.defined_funcs, ["Rec", "Rec"]) | ||
check(v.unused_funcs, []) | ||
# MyClass.Rec() is not treated as a recursive call. So, MyClass.Rec is marked as used, causing Rec to also | ||
# be marked as used (in Vulture's current behaviour) since they share the same name. | ||
|
||
|
||
def test_recursion4(v): | ||
v.scan( | ||
"""\ | ||
def Rec(): | ||
Rec() | ||
class MyClass: | ||
def __init__(self): | ||
pass | ||
def Rec(): | ||
pass | ||
""" | ||
) | ||
check(v.defined_funcs, ["Rec", "Rec"]) | ||
check(v.unused_funcs, ["Rec", "Rec"]) | ||
|
||
|
||
def test_recursion5(v): | ||
v.scan( | ||
"""\ | ||
def rec(): | ||
if (5 > 4): | ||
rec() | ||
def outer(): | ||
def inner(): | ||
outer() # these calls aren't considered for recursion | ||
inner() | ||
""" | ||
) | ||
check(v.defined_funcs, ["rec", "outer", "inner"]) | ||
check(v.unused_funcs, ["rec"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters