prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  python tempfile-without-flush: Don't require .write() for exception?
  **Describe the bug**
  The `python.lang.correctness.tempfile.flush.tempfile-without-flush` rule has [exceptions](https://github.com/returntocorp/semgrep-rules/blob/35e9f350a5d0190c936502fff179ba2c465c4438/python/lang/correctness/tempfile/flush.yaml#L5-L20) if `.write()` and then `.close()` or `.flush()` is used on a tempfile. However, this doesn't cover code which calls `.close()` immediately, without writing:
  
  ```
  $ semgrep --config=p/r2c-ci --verbose test.py
  [...]
  severity:error rule:python.lang.correctness.tempfile.flush.tempfile-without-flush: possibly missing a .flush() or .close() call to temporary file handle; file may or may not exist when handle.name is used
  3:handle = tempfile.NamedTemporaryFile(delete=False)
  4:handle.close()
  5:print(handle.name)
  ```
  
  **To Reproduce**
  ```python3
  import tempfile
  
  handle = tempfile.NamedTemporaryFile(delete=False)
  handle.close()
  print(handle.name)
  ```
  
  **Expected behavior**
  It seems to me like the exception should trigger whenever `.close()` is invoked, no matter if `.write()` is called before that or not?
  python tempfile-without-flush: Don't require .write() for exception?
  **Describe the bug**
  The `python.lang.correctness.tempfile.flush.tempfile-without-flush` rule has [exceptions](https://github.com/returntocorp/semgrep-rules/blob/35e9f350a5d0190c936502fff179ba2c465c4438/python/lang/correctness/tempfile/flush.yaml#L5-L20) if `.write()` and then `.close()` or `.flush()` is used on a tempfile. However, this doesn't cover code which calls `.close()` immediately, without writing:
  
  ```
  $ semgrep --config=p/r2c-ci --verbose test.py
  [...]
  severity:error rule:python.lang.correctness.tempfile.flush.tempfile-without-flush: possibly missing a .flush() or .close() call to temporary file handle; file may or may not exist when handle.name is used
  3:handle = tempfile.NamedTemporaryFile(delete=False)
  4:handle.close()
  5:print(handle.name)
  ```
  
  **To Reproduce**
  ```python3
  import tempfile
  
  handle = tempfile.NamedTemporaryFile(delete=False)
  handle.close()
  print(handle.name)
  ```
  
  **Expected behavior**
  It seems to me like the exception should trigger whenever `.close()` is invoked, no matter if `.write()` is called before that or not?
  
  </issue>
  <code>
  [start of python/lang/correctness/tempfile/flush.py]
  1 import tempfile
  2 
  3 import at
  4 import tf
  5 
  6 
  7 def main():
  8     with tempfile.NamedTemporaryFile("w") as fout:
  9         debug_print(astr)
  10         fout.write(astr)
  11         # ok:tempfile-without-flush
  12         fout.flush()
  13         cmd = [binary_name, fout.name, *[str(path) for path in targets]]
  14 
  15 
  16 def main_b():
  17     with tempfile.NamedTemporaryFile("w") as fout:
  18         debug_print(astr)
  19         fout.write(astr)
  20         # ok:tempfile-without-flush
  21         fout.close()
  22         cmd = [binary_name, fout.name, *[str(path) for path in targets]]
  23 
  24 
  25 def main_c():
  26     with tempfile.NamedTemporaryFile("w") as fout:
  27         debug_print(astr)
  28         fout.write(astr)
  29 
  30     # ok:tempfile-without-flush
  31     cmd = [binary_name, fout.name, *[str(path) for path in targets]]
  32 
  33 
  34 def main_c():
  35     with tempfile.NamedTemporaryFile("w") as fout:
  36         debug_print(astr)
  37         fout.write(astr)
  38         debug_print('wrote file')
  39 
  40         # ruleid:tempfile-without-flush
  41         cmd = [binary_name, fout.name, *[str(path) for path in targets]]
  42 
  43 
  44 def main_d():
  45     fout = tempfile.NamedTemporaryFile('w')
  46     debug_print(astr)
  47     fout.write(astr)
  48 
  49     # ruleid:tempfile-without-flush
  50     fout.name
  51     # ruleid:tempfile-without-flush
  52     cmd = [binary_name, fout.name, *[str(path) for path in targets]]
  53 
  54 
  55 def main_e():
  56     fout = tempfile.NamedTemporaryFile('w')
  57     debug_print(astr)
  58     fout.write(astr)
  59 
  60     # ruleid:tempfile-without-flush
  61     print(fout.name)
  62     # ruleid:tempfile-without-flush
  63     cmd = [binary_name, fout.name, *[str(path) for path in targets]]
  64
  [end of python/lang/correctness/tempfile/flush.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/tempfile/flush.py b/python/lang/correctness/tempfile/flush.py
  --- a/python/lang/correctness/tempfile/flush.py
  +++ b/python/lang/correctness/tempfile/flush.py
  @@ -61,3 +61,12 @@
       print(fout.name)
       # ruleid:tempfile-without-flush
       cmd = [binary_name, fout.name, *[str(path) for path in targets]]
  +
  +
  +def main_f():
  +    fout = tempfile.NamedTemporaryFile('w', delete=False)
  +    debug_print(astr)
  +    fout.close()
  +
  +    # ok:tempfile-without-flush
  +    print(fout.name)
  
verification_info: {"golden_diff": "diff --git a/python/lang/correctness/tempfile/flush.py b/python/lang/correctness/tempfile/flush.py\n--- a/python/lang/correctness/tempfile/flush.py\n+++ b/python/lang/correctness/tempfile/flush.py\n@@ -61,3 +61,12 @@\n     print(fout.name)\n     # ruleid:tempfile-without-flush\n     cmd = [binary_name, fout.name, *[str(path) for path in targets]]\n+\n+\n+def main_f():\n+    fout = tempfile.NamedTemporaryFile('w', delete=False)\n+    debug_print(astr)\n+    fout.close()\n+\n+    # ok:tempfile-without-flush\n+    print(fout.name)\n", "issue": "python tempfile-without-flush: Don't require .write() for exception?\n**Describe the bug**\r\nThe `python.lang.correctness.tempfile.flush.tempfile-without-flush` rule has [exceptions](https://github.com/returntocorp/semgrep-rules/blob/35e9f350a5d0190c936502fff179ba2c465c4438/python/lang/correctness/tempfile/flush.yaml#L5-L20) if `.write()` and then `.close()` or `.flush()` is used on a tempfile. However, this doesn't cover code which calls `.close()` immediately, without writing:\r\n\r\n```\r\n$ semgrep --config=p/r2c-ci --verbose test.py\r\n[...]\r\nseverity:error rule:python.lang.correctness.tempfile.flush.tempfile-without-flush: possibly missing a .flush() or .close() call to temporary file handle; file may or may not exist when handle.name is used\r\n3:handle = tempfile.NamedTemporaryFile(delete=False)\r\n4:handle.close()\r\n5:print(handle.name)\r\n```\r\n\r\n**To Reproduce**\r\n```python3\r\nimport tempfile\r\n\r\nhandle = tempfile.NamedTemporaryFile(delete=False)\r\nhandle.close()\r\nprint(handle.name)\r\n```\r\n\r\n**Expected behavior**\r\nIt seems to me like the exception should trigger whenever `.close()` is invoked, no matter if `.write()` is called before that or not?\npython tempfile-without-flush: Don't require .write() for exception?\n**Describe the bug**\r\nThe `python.lang.correctness.tempfile.flush.tempfile-without-flush` rule has [exceptions](https://github.com/returntocorp/semgrep-rules/blob/35e9f350a5d0190c936502fff179ba2c465c4438/python/lang/correctness/tempfile/flush.yaml#L5-L20) if `.write()` and then `.close()` or `.flush()` is used on a tempfile. However, this doesn't cover code which calls `.close()` immediately, without writing:\r\n\r\n```\r\n$ semgrep --config=p/r2c-ci --verbose test.py\r\n[...]\r\nseverity:error rule:python.lang.correctness.tempfile.flush.tempfile-without-flush: possibly missing a .flush() or .close() call to temporary file handle; file may or may not exist when handle.name is used\r\n3:handle = tempfile.NamedTemporaryFile(delete=False)\r\n4:handle.close()\r\n5:print(handle.name)\r\n```\r\n\r\n**To Reproduce**\r\n```python3\r\nimport tempfile\r\n\r\nhandle = tempfile.NamedTemporaryFile(delete=False)\r\nhandle.close()\r\nprint(handle.name)\r\n```\r\n\r\n**Expected behavior**\r\nIt seems to me like the exception should trigger whenever `.close()` is invoked, no matter if `.write()` is called before that or not?\n", "before_files": [{"content": "import tempfile\n\nimport at\nimport tf\n\n\ndef main():\n    with tempfile.NamedTemporaryFile(\"w\") as fout:\n        debug_print(astr)\n        fout.write(astr)\n        # ok:tempfile-without-flush\n        fout.flush()\n        cmd = [binary_name, fout.name, *[str(path) for path in targets]]\n\n\ndef main_b():\n    with tempfile.NamedTemporaryFile(\"w\") as fout:\n        debug_print(astr)\n        fout.write(astr)\n        # ok:tempfile-without-flush\n        fout.close()\n        cmd = [binary_name, fout.name, *[str(path) for path in targets]]\n\n\ndef main_c():\n    with tempfile.NamedTemporaryFile(\"w\") as fout:\n        debug_print(astr)\n        fout.write(astr)\n\n    # ok:tempfile-without-flush\n    cmd = [binary_name, fout.name, *[str(path) for path in targets]]\n\n\ndef main_c():\n    with tempfile.NamedTemporaryFile(\"w\") as fout:\n        debug_print(astr)\n        fout.write(astr)\n        debug_print('wrote file')\n\n        # ruleid:tempfile-without-flush\n        cmd = [binary_name, fout.name, *[str(path) for path in targets]]\n\n\ndef main_d():\n    fout = tempfile.NamedTemporaryFile('w')\n    debug_print(astr)\n    fout.write(astr)\n\n    # ruleid:tempfile-without-flush\n    fout.name\n    # ruleid:tempfile-without-flush\n    cmd = [binary_name, fout.name, *[str(path) for path in targets]]\n\n\ndef main_e():\n    fout = tempfile.NamedTemporaryFile('w')\n    debug_print(astr)\n    fout.write(astr)\n\n    # ruleid:tempfile-without-flush\n    print(fout.name)\n    # ruleid:tempfile-without-flush\n    cmd = [binary_name, fout.name, *[str(path) for path in targets]]\n", "path": "python/lang/correctness/tempfile/flush.py"}]}