code: def userhome(username=None):
      
      if username is None:
          # get home directory for the current user
          if 'HOME' in os.environ:
              userhome_dpath = os.environ['HOME']
          else:  # nocover
              if sys.platform.startswith('win32'):
                  # win32 fallback when HOME is not defined
                  if 'USERPROFILE' in os.environ:
                      userhome_dpath = os.environ['USERPROFILE']
                  elif 'HOMEPATH' in os.environ:
                      drive = os.environ.get('HOMEDRIVE', '')
                      userhome_dpath = join(drive, os.environ['HOMEPATH'])
                  else:
                      raise OSError("Cannot determine the user's home directory")
              else:
                  # posix fallback when HOME is not defined
                  import pwd
                  userhome_dpath = pwd.getpwuid(os.getuid()).pw_dir
      else:
          # A specific user directory was requested
          if sys.platform.startswith('win32'):  # nocover
              # get the directory name for the current user
              c_users = dirname(userhome())
              userhome_dpath = join(c_users, username)
              if not exists(userhome_dpath):
                  raise KeyError('Unknown user: {}'.format(username))
          else:
              import pwd
              try:
                  pwent = pwd.getpwnam(username)
              except KeyError:  # nocover
                  raise KeyError('Unknown user: {}'.format(username))
              userhome_dpath = pwent.pw_dir
      return userhome_dpath
docs: Returns the user's home directory.
      If `username` is None, this is the directory for the current user.
  
      Args:
          username (str): name of a user on the system
  
      Returns:
          PathLike: userhome_dpath: path to the home directory
  
      Example:
          >>> import getpass
          >>> username = getpass.getuser()
          >>> assert userhome() == expanduser('~')
          >>> assert userhome(username) == expanduser('~')