lordmauve / pgzero

A zero-boilerplate games programming framework for Python 3, based on Pygame.
https://pygame-zero.readthedocs.io/
GNU Lesser General Public License v3.0
536 stars 189 forks source link

VSCode and Pylance: multiple "Variable" is not defined warnings #251

Closed fguillen closed 3 years ago

fguillen commented 3 years ago

Is there any way to prevent Pylance for complaining about Variable not defined?

From here: https://github.com/microsoft/pyright/issues/1688

=== Describe the bug I am developing using pgzero library and I see that Pylance is complaning about many of the definitions to not be found

This is specially annoying since I am introducing kids to programming and they are very incomfortable with all these warnings around (which is good), teaching them to ignore warnings is not a good thing I think :(

To Reproduce This is a totally valid pgzero code:

import pgzrun

WIDTH = 480
HEIGHT = 340
BACKGROUND_COLOR = (36, 34, 31)

player = Actor("arrow")

def draw():
    screen.fill(BACKGROUND_COLOR)
    player.draw()

def log():
    print("log")

clock.schedule_unique(log, 1)

pgzrun.go()

Expected behavior It should be not any "not defined warnings" but there are 3:

"Actor" is not defined Pylance "screen" is not defined Pylance "clock" is not defined Pylance

I can hide the warning in Actor and clock by adding:

from pgzero.builtins import Actor
from pgzero.builtins import clock

but for screen I didn't find any solution :/

Screenshots or Code

VS Code extension or command-line

I am running pyright by pylance as an extension in VS Code

lordmauve commented 3 years ago

I think the from pgzero.builtins import ... approach is best, as it doesn't seem easy to teach each of the type checkers about the extra builtins. The ability to import screen from there is fixed in 9fe032577c93fd89be2b844be45d951bbabb08dd.