prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  False positive for return-in-init when return in internal function
  **Describe the bug**
  
  [`return-in-init`](https://github.com/returntocorp/semgrep-rules/blob/master/python/lang/correctness/return-in-init.yaml) warns about a return statement in `__init__`. However, this may be valid if another function is defined within `__init__` and return is used there.
  
  **To Reproduce**
  
  ```
  class Odd:
      def __init__(self, numbers):
          def is_odd(n):
              return n % 2 == 1
          self.numbers = filter(is_odd, numbers)
  ```
  
  ```
  $ semgrep --config=p/ci
  test1.py
  severity:error rule:python.lang.correctness.return-in-init.return-in-init: `return` should never appear inside a class __init__ function. This will cause a runtime error.
  4:            return n % 2 == 1
  ```
  
  **Expected behavior**
  
  I expect no error from `return-in-init` in this case.
  
  **Priority**
  How important is this to you?
  - P2: annoying but not blocking me
  
  
  </issue>
  <code>
  [start of python/lang/correctness/return-in-init.py]
  1 class A:
  2     def __init__(a, b, c):
  3         # ruleid:return-in-init
  4         return A(a, b, c)
  5 
  6 
  7 class B:
  8     def __init__(a, b, c):
  9         # ok:return-in-init
  10         return
  11 
  12 
  13 class C:
  14     def __init__(a, b, c):
  15         # ruleid:yield-in-init
  16         yield
  17 
  18 
  19 class D:
  20     def __init__():
  21         # ruleid:yield-in-init
  22         yield 5
  23 
  24 
  25 def __init__(a, b, c):
  26     # ok:yield-in-init
  27     return A(a, b, c)
  28 
  29 
  30 def __init__(a, b, c):
  31     # ok:yield-in-init
  32     yield
  33 
  34 
  35 def __init__():
  36     # ok:yield-in-init
  37     yield 5
  38 
  39 
  40 class E:
  41     def func1():
  42         if not hello:
  43             # ok:yield-in-init
  44             yield 5
  45         # ok:yield-in-init
  46         yield other
  47 
  48 
  49 class F:
  50     def __init__():
  51         pass
  52 
  53     def func1():
  54         # ok:return-in-init
  55         return 5
  56 
  57     def func2():
  58         # ok:return-in-init
  59         return
  60 
  61 
  62 class G:
  63     def __init__():
  64         pass
  65 
  66     def func1():
  67         # ok:yield-in-init
  68         yield 5
  69 
  70     def func2():
  71         # ok:yield-in-init
  72         yield
  73 
  74 class H:
  75     def __init__(self, x):
  76         # ok:return-in-init
  77         return None
  78
  [end of python/lang/correctness/return-in-init.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/python/lang/correctness/return-in-init.py b/python/lang/correctness/return-in-init.py
  --- a/python/lang/correctness/return-in-init.py
  +++ b/python/lang/correctness/return-in-init.py
  @@ -75,3 +75,41 @@
       def __init__(self, x):
           # ok:return-in-init
           return None
  +
  +class Odd:
  +    def __init__(self, numbers):
  +        def is_odd(n):
  +            # ok:return-in-init
  +            return n % 2 == 1
  +        self.numbers = filter(is_odd, numbers)
  +
  +        # todoruleid:return-in-init
  +        return self.numbers
  +
  +class Even:
  +    def __init__(self):
  +        class EvenNumber:
  +            def __init__(self, n):
  +                self.n = n
  +                # todoruleid:return-in-init
  +                return n
  +
  +            def is_even(self):
  +                # ok:return-in-init
  +                return self.n % 2 == 0
  +
  +        self.number = EvenNumber()
  +
  +    def not_init(self):
  +        class EvenNumber:
  +            def __init__(self, n):
  +                self.n = n
  +                # ruleid:return-in-init
  +                return n
  +
  +            def is_even(self):
  +                # ok:return-in-init
  +                return self.n % 2 == 0
  +
  +        # ok:return-in-init
  +        return EvenNumber()
  
verification_info: {"golden_diff": "diff --git a/python/lang/correctness/return-in-init.py b/python/lang/correctness/return-in-init.py\n--- a/python/lang/correctness/return-in-init.py\n+++ b/python/lang/correctness/return-in-init.py\n@@ -75,3 +75,41 @@\n     def __init__(self, x):\n         # ok:return-in-init\n         return None\n+\n+class Odd:\n+    def __init__(self, numbers):\n+        def is_odd(n):\n+            # ok:return-in-init\n+            return n % 2 == 1\n+        self.numbers = filter(is_odd, numbers)\n+\n+        # todoruleid:return-in-init\n+        return self.numbers\n+\n+class Even:\n+    def __init__(self):\n+        class EvenNumber:\n+            def __init__(self, n):\n+                self.n = n\n+                # todoruleid:return-in-init\n+                return n\n+\n+            def is_even(self):\n+                # ok:return-in-init\n+                return self.n % 2 == 0\n+\n+        self.number = EvenNumber()\n+\n+    def not_init(self):\n+        class EvenNumber:\n+            def __init__(self, n):\n+                self.n = n\n+                # ruleid:return-in-init\n+                return n\n+\n+            def is_even(self):\n+                # ok:return-in-init\n+                return self.n % 2 == 0\n+\n+        # ok:return-in-init\n+        return EvenNumber()\n", "issue": "False positive for return-in-init when return in internal function\n**Describe the bug**\r\n\r\n[`return-in-init`](https://github.com/returntocorp/semgrep-rules/blob/master/python/lang/correctness/return-in-init.yaml) warns about a return statement in `__init__`. However, this may be valid if another function is defined within `__init__` and return is used there.\r\n\r\n**To Reproduce**\r\n\r\n```\r\nclass Odd:\r\n    def __init__(self, numbers):\r\n        def is_odd(n):\r\n            return n % 2 == 1\r\n        self.numbers = filter(is_odd, numbers)\r\n```\r\n\r\n```\r\n$ semgrep --config=p/ci\r\ntest1.py\r\nseverity:error rule:python.lang.correctness.return-in-init.return-in-init: `return` should never appear inside a class __init__ function. This will cause a runtime error.\r\n4:            return n % 2 == 1\r\n```\r\n\r\n**Expected behavior**\r\n\r\nI expect no error from `return-in-init` in this case.\r\n\r\n**Priority**\r\nHow important is this to you?\r\n- P2: annoying but not blocking me\r\n\n", "before_files": [{"content": "class A:\n    def __init__(a, b, c):\n        # ruleid:return-in-init\n        return A(a, b, c)\n\n\nclass B:\n    def __init__(a, b, c):\n        # ok:return-in-init\n        return\n\n\nclass C:\n    def __init__(a, b, c):\n        # ruleid:yield-in-init\n        yield\n\n\nclass D:\n    def __init__():\n        # ruleid:yield-in-init\n        yield 5\n\n\ndef __init__(a, b, c):\n    # ok:yield-in-init\n    return A(a, b, c)\n\n\ndef __init__(a, b, c):\n    # ok:yield-in-init\n    yield\n\n\ndef __init__():\n    # ok:yield-in-init\n    yield 5\n\n\nclass E:\n    def func1():\n        if not hello:\n            # ok:yield-in-init\n            yield 5\n        # ok:yield-in-init\n        yield other\n\n\nclass F:\n    def __init__():\n        pass\n\n    def func1():\n        # ok:return-in-init\n        return 5\n\n    def func2():\n        # ok:return-in-init\n        return\n\n\nclass G:\n    def __init__():\n        pass\n\n    def func1():\n        # ok:yield-in-init\n        yield 5\n\n    def func2():\n        # ok:yield-in-init\n        yield\n\nclass H:\n    def __init__(self, x):\n        # ok:return-in-init\n        return None\n", "path": "python/lang/correctness/return-in-init.py"}]}