'%s %r has no %r member%s'
Used when a variable is accessed for an unexistent member.
Pylint infers (guesses) the types of expressions in the analyzed code and checks whether the used attributes and methods exist in the type that it found.
In the example we try to access the method
not_a_method_of_int on an instance
int and the function
unknown_func on the module
math. Both do not
exists and so Pylint warns us.
import math def main(): a = 1 b = a.not_a_method_of_int() print(math.unknown_func(b))
5:8: E1101: Instance of 'int' has no 'not_a_method_of_int' member 6:10: E1101: Module 'math' has no 'unknown_func' member
Pylint also can check whether access to a method or attribute of
class A: pass class B(A): def method(self): return super().method()
6:15: E1101: Super of 'B' has no 'method' member
If the inference mechanism gets the type of an expression wrong or does not understand it, Pylint will emit warnings that are not justified. Unfortunately, the dynamic nature of Python programms and the use of meta-programming make this scenario pretty common.
In the following example the use of
setattr (which classifies as
meta-programming) leads to a unjustified warning.
class A: def __init__(self): setattr(self, "attribute", 1) def main(): a = A() print(a.attribute)
7:10: E1101: Instance of 'A' has no 'attribute' member
Many libraries and common patterns make it hard for Pylint to infer the right types. Popular examples are the declarative APIs offered by many ORMs, like SQLAlchemy or Django ORM. There are Pylint plugins that try to alleviate the problem, e.g. pylint-django.
If Pylint does not have information about the type of an expression, it cannot
warn about a missing member. In the example, we use
pytz (a python timezone library)
and access an attribute that does not exist.
import pytz def main(): utc = pytz.utc print(utc.not_an_attribute_of_tz)
No issues found.
This is why it is important to have the dependencies of a project installed when analyzing it with Pylint.