2

I am using a metaclass in my code, and the code works. (Using a metaclass, it sets the attribute test_attr to "Success!" on object creation.) When I run pylint on this code, however, it displays errors in Test.test, saying that test_attr is not defined.

class MyMeta(type):
    def __new__(mcs, name, bases, attrs):
        attrs["test_attr"] = "Success!"
        return super().__new__(mcs, name, bases, attrs)


class Test(metaclass=MyMeta):
    def test(self):
        return self.test_attr

What should I do to satisfy pylint? Is there a configuration option to fix this? Is there something about my code that I should fix?

1 Answer 1

1

I'm guessing pylint simply doesn't understand this kind of "magic" - why are you doing it in the first place?

You could set generated-members or ignored-classes (see docs) to tell pylint about it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.