Home > Software design >  E1101 (no-member) for code that works well
E1101 (no-member) for code that works well

Time:01-21

I have a structure similar to below, in my code:

class A():
    def __init__(
            self,
            <SOME_VARIABLES>
            )
            self.matrix = self._get_matrix()

class B(A):
    def __init__(
            self,
            <SOME_VARIABLES>
            )
        super().__init__(
            <SOME_VARIABLES>
            )

    def _get_matrix(self):
        <DO SOMETHING>

class C(A):
    def __init__(
            self,
            <SOME_VARIABLES>
            )
        super().__init__(
            <SOME_VARIABLES>
            )

    def _get_matrix(self):
        <DO SOMETHING>

The code works fine. However, Pylint returns an E1101(no-member) error. How can I change my code so I don't get this error?

The _get_matrix() methods in classes B and C work differently, so I cannot place them in A.

CodePudding user response:

Mark A as abstract base class using abc module, then add method signature of _get_matrix to A.

from abc import ABC, abstractmethod

class A(ABC):
    def __init__(
            self,
            <SOME_VARIABLES>
            )
            self.matrix = self._get_matrix()
    @abstractmethod
    def _get_matrix(self):
        raise NotImplementedError()
  • Related