PyCharm not detecting errors raised by metaclasses

# I have roughly the following code:
import abc

class Metaclass(abc.ABCMeta):
def __new__(mcs, *args, **kwargs):
new = super().__new__(mcs, *args, **kwargs)
if not hasattr(new, "foo"):
raise AttributeError("Descendents of 'Meta' must contain a 'foo'")
return new

class Class(metaclass=Metaclass):
# This class will always raise an AttributeError
# when the interpreter reaches the declaration

if __name__ == "__main__":
test = Class()
# This is guaranteed behavior, however PyCharm doesn't
# detect this as it would with code such as the following:
import abc

class Interface(abc.ABC):
def foo(self):

class Class(Interface):
# 'Class' is presently highlighted in yellow with the error 'class Class must implement all abstract methods'

if __name__ == "__main__":
test = Class()

# I would hope that behavior such as the first program
# could be implemented, as to eliminate bugs.

1 comment


Thank you for the report!

It's a known issue. Please vote for it on our tracker to get notifications when there are any updates.


Please sign in to leave a comment.