Janis Lesinskis' Blog

Assorted ramblings

  • All entries
  • About me
  • Projects
  • Economics
  • Misc
  • Software-engineering
  • Sports

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.

Published: Tue 14 April 2020
By Janis Lesinskis
In Software-engineering
Tags: software-engineering linting python python-c-API security pylint

links

  • JaggedVerge

social

  • My GitHub page
  • LinkedIn

Proudly powered by Pelican, which takes great advantage of Python.