0

For example the following (silly) example will raise an error within vscode:

class Something:
    def __init__(self, x):
        self.x = x

    def something_else(self, y) -> Something:
        return Something(self.x + y)

Seen here:

enter image description here

Where as mypy script.py will return no errors.

I'm not sure what the difference is here, but I'd rather mypy took priority as that's what I'm using to catch type errors.

baxx
  • 3,956
  • 6
  • 37
  • 75

1 Answers1

1

Something isn't defined as it won't be defined until the class definition is complete. You'll notice that running this code will cause a NameError, so in this case Pylance and Pylint are correct and you probably shouldn't silence their warnings.

Refer to this question for how to fix that.

Miguel Guthridge
  • 1,444
  • 10
  • 27