Avoid Pylint warning E1101: 'Instance of .. has no .. member' for class with dynamic attributes

后端 未结 6 1650
走了就别回头了
走了就别回头了 2020-11-27 04:02

Imagine a function which dynamically adds attributes to an object using setattr. The reason for doing so is that I want to map some external structure

6条回答
  •  抹茶落季
    2020-11-27 04:53

    Try this! My problem solved!

    Pylint doesn't understand the Django's dynamic filed. Thus, we need to teach what the Django is to Pylint

    *for vscode in Windows 10 *

    $ pip install pylint-django
    $ cd your_project_folder
    $ code . // run vscode  
    

    Install extension for Python, Django Snippets, Django Template in vscode

    Open .vscode/settings.json in vscode and add:

    {
       "python.linting.pylintEnabled": true,
       "python.linting.enabled": true,
       "python.pythonPath": "venv\\Scripts\\python.exe",
       "python.linting.pylintArgs": [
           "--load-plugins",
           "pylint_django"
       ],
    }
    

提交回复
热议问题