'Hide calltip when necessary'

def hide_tooltip_if_necessary(self, key):

    try:
        calltip_char = self.get_character(self.calltip_position)
        before = self.is_cursor_before(self.calltip_position, char_offset=1)
        other = (key in (Qt.Key_ParenRight, Qt.Key_Period, Qt.Key_Tab))
        if ((calltip_char not in ('?', '(')) or before or other):
            QToolTip.hideText()
    except (IndexError, TypeError):
        QToolTip.hideText()
