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
PyLint gives this type of errors on two cases Link:
Used when an object (variable, function, …) is accessed for a non-existent member.
False positives: This message may report object members that are created dynamically, but exist at the time they are accessed.
As this error is identified as E1101 error. You can solve the issue by adding the following line in your code.
# pylint: disable=E1101
For me just installing pylint-django solved the issue:
pip install pylint-django
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"
],
}
Just to provide the answer that works for me now - as The Compiler suggested you can add a rule for the problematic class in your projects .pylintrc
:
[TYPECHECK]
ignored-classes=Fysom,MyClass
This page describes the error and gives an easy way to address it directly in the code. tl;dr
Used when an object (variable, function, …) is accessed for a non-existent member.
False positives: This message may report object members that are created dynamically, but exist at the time they are accessed.
A commentor mentions that it can be disabled on a single line at the top of the file with # pylint: disable=no-member
. I also found that you can use # pylint: disable=E1101
based on this reddit entry.
I was able to avoid this warning by adding the __getattr__
method to my class, which python calls when an attribute is not found on an object. Although definitely not the cleanest solution, it worked for my particular use-case as pylint considers the object valid.
import warnings
class AppConfiguration(object):
...
def __getattr__(self, name):
''' will only get called for undefined attributes '''
warnings.warn('No member "%s" contained in settings config.' % name)
return ''
More information about the __getattr__
method can be found here.