Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show errors in Python code with VSCode

I would like to configure VSCode in such a way that I can see red squiggly lines when there is an error in my python code.

My VSCode currently shows me Python syntax errors (e.g. pri nt("hello") will have a red squiggly line), but not the following errors:

class Dog:
    attr1 = "mammal"
    attr2 = "dog"

    def fun(self):
        print("I'm a", self.attr1)
        print("I'm a", self.attr3)


Rodger = Dog()

print(Rodger.attr1)
Rodger.bark()

In the code above I would like to see a red squiggly line on print("I'm a", self.attr3) since this object doesn't have a self.attr3 attribute, and Rodger.bark() since this object doesn't have a bark method.

like image 611
benji Avatar asked Aug 14 '26 09:08

benji


1 Answers

You will need linters like Pylint which is supported by vscode. From the docs:

linting detects use of an uninitialized or undefined variable, calls to undefined functions, missing parentheses, and even more subtle issues such as attempting to redefine built-in types or functions.

After that you will need to turn on strict mode. Here is the link on how to do that. Microsoft explains it better than I can do on how to set it up.

like image 101
ClassY Avatar answered Aug 16 '26 09:08

ClassY