docs: def os_replace(src, dst):
      '''
      Simple emulation of function `os.replace(..)` from modern version
      of Python. Implementation is not fully atomic, but enough for us.
      '''
  
      orig_os_replace_func = getattr(os, 'replace', None)
  
      if orig_os_replace_func is not None:
          # not need for emulation: we using modern version of Python.
          # fully atomic for this case
  
          orig_os_replace_func(src, dst)
          return
  
      if os.name == 'posix':
          # POSIX requirement: `os.rename(..)` works as `os.replace(..)`
          # fully atomic for this case
  
          os.rename(src, dst)
          return
  
      # simple emulation for `os.name == 'nt'` and other marginal
      # operation systems.  not fully atomic implementation for this
      # case
  
      try:
          # trying atomic `os.rename(..)` without `os.remove(..)` or
          # other operations
  
          os.rename(src, dst)
          error = None
      except OSError as e:
          error = e
  
      if error is None:
          return
  
      for i in range(5):
          # some number of tries may be failed
          # because we may be in concurrent environment with other
          # processes/threads
  
          try:
              os.remove(dst)
          except OSError:
              # destination was not exist
              # or concurrent process/thread is removing it in parallel with us
              pass
  
          try:
              os.rename(src, dst)
              error = None
          except OSError as e:
              error = e
              continue
  
          break
  
      if error is not None:
          raise_from(OSError('failed to replace'), error)