<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def set_filetype(self, filetype, bufnr=None):
 """Set filetype for a buffer. Note: it's a quirk of Vim's Python API that using the buffer.options dictionary to set filetype does not trigger ``FileType`` autocommands, hence this implementation executes as a command instead. Args: filetype (str):
 The filetype to set. bufnr (Optional[int]):
 A Vim buffer number, current if ``None``. """

        if bufnr:
            self._vim.command(str(bufnr) + 'bufdo set filetype=' + filetype)
        else:
            self._vim.command('set filetype=' + filetype)