def METHOD_NAME(self, linenum, type):
    """Marks the given line number with a mark of the given type."""
    nums = [mark.blockNumber() for mark in self._marks[type]]
    if linenum in nums:
        return
    index = bisect.bisect_left(nums, linenum)
    mark = QTextCursor(self.document().findBlockByNumber(linenum))
    try:
        # only available in very recent PyQt5 versions
        mark.setKeepPositionOnInsert(True)
    except AttributeError:
        pass
    self._marks[type].insert(index, mark)
    self.marksChanged()