import sys
import os


if sys.platform.startswith('win'):
    def rename_file(current_filename, new_filename):
        try:
            os.remove(new_filename)
        except OSError:
            pass
        os.rename(current_filename, new_filename)
else:
    rename_file = os.rename

import sys
import os
import errno


if sys.platform.startswith('win'):
    def rename_file(current_filename, new_filename):
        try:
            os.remove(new_filename)
        except OSError as e:
            if not e.errno == errno.ENOENT:
                # We only want to a ignore trying to remove
                # a file that does not exist.  If it fails
                # for any other reason we should be propagating
                # that exception.
                raise
        os.rename(current_filename, new_filename)
else:
    rename_file = os.rename

Handle the case where OSError is not because file does not exist
Handle the case where OSError is not because file does not exist

  import sys
  import os
+ import errno
  
  
  if sys.platform.startswith('win'):
      def rename_file(current_filename, new_filename):
          try:
              os.remove(new_filename)
-         except OSError:
+         except OSError as e:
+             if not e.errno == errno.ENOENT:
+                 # We only want to a ignore trying to remove
+                 # a file that does not exist.  If it fails
+                 # for any other reason we should be propagating
+                 # that exception.
-             pass
+                 raise
          os.rename(current_filename, new_filename)
  else:
      rename_file = os.rename
  
Handle the case where OSError is not because file does not exist
## Code Before:
import sys
import os


if sys.platform.startswith('win'):
    def rename_file(current_filename, new_filename):
        try:
            os.remove(new_filename)
        except OSError:
            pass
        os.rename(current_filename, new_filename)
else:
    rename_file = os.rename

## Instruction:
Handle the case where OSError is not because file does not exist
## Code After:
import sys
import os
import errno


if sys.platform.startswith('win'):
    def rename_file(current_filename, new_filename):
        try:
            os.remove(new_filename)
        except OSError as e:
            if not e.errno == errno.ENOENT:
                # We only want to a ignore trying to remove
                # a file that does not exist.  If it fails
                # for any other reason we should be propagating
                # that exception.
                raise
        os.rename(current_filename, new_filename)
else:
    rename_file = os.rename
