pylint
pylint copied to clipboard
False positive for pygame.PixelArray(surface) "E1121:Too many positional arguments for lambda call"
Steps to reproduce
- I'm using vscode, and here are my workspace settings
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.linting.pylintArgs": [
"--extension-pkg-whitelist=pygame",
"--disable=W,C"
],
}
- My code, (I was attempting to run the code given on https://inventwithpython.com/pygame/chapter2.html)
import sys
import pygame
from pygame.locals import *
pygame.init()
# setup the window
DISPLAYSURF = pygame.display.set_mode((500, 400), 0, 32)
pygame.display.set_caption("Drawing")
# setup the colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
pixObj = pygame.PixelArray(DISPLAYSURF)
pixObj[480][380] = BLACK
pixObj[482][382] = BLACK
pixObj[484][384] = BLACK
pixObj[486][386] = BLACK
pixObj[488][388] = BLACK
del pixObj
Current behavior
As mentioned I get an error at the line
pixObj = pygame.PixelArray(DISPLAYSURF)
As,
E1121:Too many positional arguments for lambda call
Expected behavior
There shouldn't be an error in the linter output,
I tried flake8 besides pylint, and that doesn't give an error.
pylint --version output
No config file found, using default configuration pylint 1.8.4, astroid 1.6.3 Python 3.6.3 |Anaconda custom (64-bit)| (default, Oct 15 2017, 03:27:45) [MSC v.1900 64 bit (AMD64)]
flake8 doesn't have the checks that pylint has, so not sure why it was worth bringing it in discussion.
But this looks like a bug in pylint, there might be something going on with PixelArray that we don't understand.
Similar false positive occurs for pygame.Surface.
Code:
class Wall(pygame.sprite.Sprite):
def __init__(self, x, y, width, height, color):
super().__init__()
# Create the "image" for our wall
self.image = pygame.Surface([width, height])
self.image.fill(color)
# the x and y variables become the top left corner
self.rect = self.image.get_rect()
self.rect.y = y
self.rect.x = x
Linter output: E1121:Too many positional arguments for lambda call (on line self.image = pygame.Surface([width, height]), col 22)
And because the opening report did it: pylint --version output:
No config file found, using default configuration
pylint 1.7.4,
astroid 1.5.3
Python 3.6.6 (default, Jun 27 2018, 13:11:40)
[GCC 8.1.1 20180531]
There's probably other Pygame false positives, since Surface is set up in __init__.py in a similar manner to Overlay, Mask, and the pygame.time and pygame.transform modules.
This issue occurs because pygame does:
try:
from pygame.surface import *
except (ImportError, IOError):
Surface = lambda: Missing_Function
and astroid infers Surface could be a lambda with no arguments.
(also surface is .so file which appears to be uninferable)
Kind of a control flow issue which is a long way off. Maybe a astroid/brain tip for pygame would be the best way to go if someone wants to write one (see https://github.com/PyCQA/astroid/tree/master/astroid/brain)
A work around would be to explictly import these classes from their submodules:
from pygame import surface
surface.Surface([1,2])
Lints correctly