Isn't what I wrote exactly equivalent to what is currently there?

    if getattr(document, 'editorconfig_whitespace_handler', None):
        # The trimmer exists, so remove it if necessary:
        if not trim_trailing_whitespace:
            document.disconnect(document.editorconfig_whitespace_handler)
            document.editorconfig_whitespace_handler = None
    else:
        # The trimmer does not exist, so install it if necessary:
        if trim_trailing_whitespace:
            handler_id = document.connect('save', trim_whitespace_on_save)
            document.editorconfig_whitespace_handler = handler_id