Pylint false positives with C extensions
Recently I was working with some code that is implemented in a Python C extension. Pylint was throwing up some clearly false-positive errors for missing members. This is a good example of such behavior:
import pygame
pygame.init()
This will give the following Pylint error:
$ pylint false_positive_pylint.py
false_positive_pylint.py:2:0: E1101: Module 'pygame' has no 'init' member (no-member)
This is clearly a false positive. The reason this issue comes up is because pygame implements this particular method in C and for security reasons Pylint will not execute any user supplied C extension code due to the security risks that arbitrary code execution opens up.
If you would like to instruct Pylint to execute this code you can by changing the configuration, for example in .pylintrc
add the following:
extension-pkg-whitelist=pygame
This tells Pylint that it's OK to analyse the compiled code in the pygame
module and the false negatives go away.