Zettelkasten

python MetaClass 다중상속 문제

·수정 2026.04.24·수정 2

MetaClass 다중상속 문제

  • 메타클래스를 2개 이상 상속할 수 없는 문제가 있음
TypeError: metaclass conflict: the metaclass of a derived class must be

문제 원인: 메타클래스는 클래스의 구조를 정의하고 생성을 제어한느 역할을 하는데, 여러 메타 클래스를 상속하게 되면, 호출 순위와 우선순위를 파악할 수 없게됨

http://batmask.net/index.php/2020/04/14/402/

  1. 그냥 상속 받을 때, 하나의 메타클래스만 사용하기
  2. metaclass를 사용하지 않고 구현하고 override하지 않으면 NotImplement 에러 발생시키는 방식으로 구현
class ISomeClass:
    def this_is_method(self, arg):
         raise NoatImplementError

파이썬 메타클래스는 클래스의 생성과 동작을 제어한다