def _delete_reg_key(root, key_path, verbose=False):
    """Helper to delete a registry key, ignoring if not found."""
    rootkey_name = "HKEY_CURRENT_USER" if root == winreg.HKEY_CURRENT_USER else "HKEY_LOCAL_MACHINE"
    if verbose:
        print(f"{rootkey_name}\\{key_path}")
    try:
        # DeleteKey can only delete keys with no subkeys.
        # For keys with (still) subkeys, use DeleteKeyEx on the parent key if available
        winreg.DeleteKey(root, key_path)
    except FileNotFoundError:
        if verbose:
             print(f"Registry key not found (skipping deletion): {rootkey_name}\\{key_path}")
    except OSError as e: # Catch other potential errors like key not empty
        print(f"Error deleting registry key {rootkey_name}\\{key_path}: {e}", file=sys.stderr)
Helper to delete a registry key, ignoring if not found.
winpython/associate.py