Closed
Description
t.py:
class A:
myfield: int
class B(A):
pass
a = A()
print(a.myfield)
b = B()
print(b.myfield)
# pylint 2.4.2, astroid 2.3.1
$ pylint t.py | grep no-member
t.py:11:6: E1101: Instance of 'B' has no 'myfield' member (no-member)
Pylint doesn't appear to "see" the subclass myfield
member declared in the parent class (reports the error against B
), but does see it in the parent class (doesn't report against A
).
(Technically I suppose the member isn't actually there in the parent class either as it's an instance variable without a default [1], and I believe they kind of spring to life only when actually set to a value which doesn't happen in this example -- for this reason the example code actually raises when run. Pylint seems to "know" that it's (or will be) there nevertheless which I think is great, but it should also know that it's there in the subclass.
[1] https://www.python.org/dev/peps/pep-0526/#class-and-instance-variable-annotations)