skip to Main Content

While developing I used

from pydantic import ValidationError
.
.
.
from jsonschema.exceptions import ValidationError

I used the first imports but further I added another second import which resulted in not catching the expected result .but vscode did not throw any error notifying about the duplicate import or something as such.

As a result I was not able to catch the expected error as the actual one was over written.

Is there a way in vscode where it will give a squilly or some warning to notify that this current import is used or over written ?

2

Answers


  1. Flake8 has a rule that warns you about redifinition.

    Considering toto.py

    from pydantic import ValidationError
    from jsonschema.exceptions import ValidationError
    

    Using flake8 via command line:

    $ flake8 toto.py
    toto.py:2:1: F811 redefinition of unused 'ValidationError' from line 1
    

    If you absolutely need it within VSCode, there is an
    extension for it:

    enter image description here

    Login or Signup to reply.
  2. You can get warnings through Linting, now you can still enable it with the following settings

        "python.linting.enabled": true,
        "python.linting.pylintEnabled": true,
    

    But it is better to install the linting extension(such as Pylint), because this is what Microsoft recommends.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search