Let me start by saying the code below is not generally the way to fix an Emacs problem. What I do is load flymake then stomp on one of the core functions. Because of the way flymake is written, I couldn't find a way to hook into a function or even use advice. And if flymake changes this function or how it's called it won't work anymore. That said, it has been working for me for years :)
This is the base code:
(require 'flymake)
(defun flymake-get-file-name-mode-and-masks (file-name)
"Return the corresponding entry from `flymake-allowed-file-name-masks'."
(unless (stringp file-name)
(error "Invalid file-name"))
(let ((fnm flymake-allowed-file-name-masks)
(mode-and-masks nil)
(matcher nil))
(while (and (not mode-and-masks) fnm)
(setq matcher (car (car fnm)))
(if (or (and (stringp matcher) (string-match matcher file-name))
(and (symbolp matcher) (equal matcher major-mode)))
(setq mode-and-masks (cdr (car fnm))))
(setq fnm (cdr fnm)))
(flymake-log 3 "file %s, init=%s" file-name (car mode-and-masks))
mode-and-masks))
Then from your code above, instead of this:
(add-to-list 'flymake-allowed-file-name-masks '("\\.py\\'" flymake-pylint-init))
do this:
(add-to-list 'flymake-allowed-file-name-masks '(python-mode flymake-pylint-init))
You could do the same for Perl, etc.