E1101: Super of has no 'append' member (no-member)

Viewed 130

I used pylint to refactor someone else's code. However, there is an error about error E1101. I don't know what to do to fix it. So to see this error, I created a simple example of the same format in that code.

This is my source example.

from typing import List

class Test:
    def __init__(self, a: int, b: float):
        self.a = a
        self.b = b

class TestSuper(List[Test]):
    # def __init__(self)
    def append(self, object_: Test):
        # do something
        return super().append(object_)

Pylint error is:

Super of 'TestSuper' has no 'append' memberpylint(no-member)
1 Answers

The following code does not produce the error.

class Test:
    def __init__(self, a: int, b: float):
        self.a = a
        self.b = b


class TestSuper(list):
    # def __init__(self)
    def append(self, object_: Test):
        # do something
        return super().append(object_)

It is questionable though why you would want to inherit from list and only add an append method that has a type hint to the object that can be appended. Questionable since the interpreter does not verify the type of the object that is appended. Appending a string for example is still possible. Example:

test_super = TestSuper()
test_super.append("x")
print(test_super)

Instead you could use the vanilla list object. Example:

class Test:
    def __init__(self, a: int, b: float):
        self.a = a
        self.b = b


test_super = ["x"]
test = Test(1, 1.0)
test_super.append(test)
print(test_super)
Related