Python: Modernise the py/explicit-return-in-init query.

Add explicit test case to show that we don't doulbe report this problem.
This commit is contained in:
Rasmus Wriedt Larsen
2019-09-18 17:19:22 +02:00
parent f0479687d8
commit 6e50a0ef84
2 changed files with 12 additions and 7 deletions

View File

@@ -13,11 +13,10 @@
import python
from Return r
where exists(Function init | init.isInitMethod() and
r.getScope() = init and exists(r.getValue())) and
not r.getValue() instanceof None and
not exists(FunctionObject f | f.getACall() = r.getValue().getAFlowNode() |
f.neverReturns()
) and
not exists(Attribute meth | meth = ((Call)r.getValue()).getFunc() | meth.getName() = "__init__")
where
exists(Function init | init.isInitMethod() and r.getScope() = init and exists(r.getValue())) and
not r.getValue() instanceof None and
not exists(FunctionValue f | f.getACall() = r.getValue().getAFlowNode() | f.neverReturns()) and
// to avoid double reporting, don't trigger if returning result from other __init__ function
not exists(Attribute meth | meth = r.getValue().(Call).getFunc() | meth.getName() = "__init__")
select r, "Explicit return in __init__ method."