0

So I'm using the library pgzero to teach kids programming. With pgzero you have this screen object you can draw to. As far as I know, you cannot import this from anywhere, it's just in the global scope. Unfortunately Pylint doesn't know about this, and i keep getting undefined-variable errors every time i use the screen object (running the code works fine, but vscode puts red lines under screen everytime I use it).

This is not very helpful when trying to teach, and can be rather distracting. I don't want to disable pylint errors completely, as they are pretty useful most of the time, and a nice tool for newcomers.

Is there any way to somehow declare the variable in the global scope? Something similar to typescript would be nice:

declare screen

Other ways of solving would be some way to disable the error for just this one variable, or if someone's familiar with pgzero: some way to import the object from. As it stands i am not able to get any intellisense on the object either, but that's not the end of the world (a solution to this would be useful).

Kris10an
  • 548
  • 3
  • 23

1 Answers1

0

I was having this problem myself, and found a solution where people had this problem with pylint in another setting.

Press control+shift+P to bring up the vscode search bar, and type in 'Open workspace settings (JSON)'. Select this option, and then set the JSON file that comes up to the following:

{
    "python.linting.pylintArgs": [
        "--additional-builtins=screen,mouse,keys"
    ]
}

Then save the JSON file.

This tells pylint to accept the names seperated by commas as words built in to python. If this problem occurs with other names, add them to this list.

Dharman
  • 30,962
  • 25
  • 85
  • 135