File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed
test/query-tests/Functions/general Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change 1313import python
1414
1515from Return r
16- where exists ( Function init | init .isInitMethod ( ) and
17- r .getScope ( ) = init and exists ( r .getValue ( ) ) ) and
18- not r .getValue ( ) instanceof None and
19- not exists ( FunctionObject f | f .getACall ( ) = r .getValue ( ) .getAFlowNode ( ) |
20- f .neverReturns ( )
21- ) and
22- not exists ( Attribute meth | meth = ( ( Call ) r .getValue ( ) ) .getFunc ( ) | meth .getName ( ) = "__init__" )
16+ where
17+ exists ( Function init | init .isInitMethod ( ) and r .getScope ( ) = init and exists ( r .getValue ( ) ) ) and
18+ not r .getValue ( ) instanceof None and
19+ not exists ( FunctionValue f | f .getACall ( ) = r .getValue ( ) .getAFlowNode ( ) | f .neverReturns ( ) ) and
20+ // to avoid double reporting, don't trigger if returning result from other __init__ function
21+ not exists ( Attribute meth | meth = r .getValue ( ) .( Call ) .getFunc ( ) | meth .getName ( ) = "__init__" )
2322select r , "Explicit return in __init__ method."
Original file line number Diff line number Diff line change @@ -37,3 +37,9 @@ class InitCallsInit(InitCallsError):
3737
3838 def __init__ (self ):
3939 return super (InitCallsInit , self ).__init__ ()
40+
41+ # This is not ok, but we will only report root cause (ExplicitReturnInInit)
42+ class InitCallsBadInit (ExplicitReturnInInit ):
43+
44+ def __init__ (self ):
45+ return ExplicitReturnInInit .__init__ (self )
You can’t perform that action at this time.
0 commit comments