Python: Don't flag return procedure_call() in __init__ as error

This commit fixes the results for
0d8a429b7e/files/mayaTools/cgm/lib/classes/AttrFactory.py (L90)

```
def __init__(...):
    if error_case:
        return guiFactory.warning(...)
```

that was wrongly reporting _Explicit return in __init__ method._ as an error.
This commit is contained in:
Rasmus Wriedt Larsen
2019-09-23 11:09:32 +02:00
parent 6e50a0ef84
commit d273974045
3 changed files with 66 additions and 7 deletions

View File

@@ -12,11 +12,12 @@
import python
from Return r
from Return r, Expr rv
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
exists(Function init | init.isInitMethod() and r.getScope() = init) and
r.getValue() = rv and
not rv.pointsTo(Value::none_()) and
not exists(FunctionValue f | f.getACall() = rv.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__")
not exists(Attribute meth | meth = rv.(Call).getFunc() | meth.getName() = "__init__")
select r, "Explicit return in __init__ method."