Shouldn't __metaclass__ force the use of a metaclass in Python?

前端 未结 3 371
日久生厌
日久生厌 2021-01-18 13:23

I\'ve been trying to learn about metaclasses in Python. I get the main idea, but I can\'t seem to activate the mechanism. As I understand it, you can specify M to be as the

3条回答
  •  离开以前
    2021-01-18 13:41

    In Python 3 (which you are using) metaclasses are specified by a keyword parameter in the class definition:

    class ClassMeta(metaclass=M):
      pass
    

    Specifying a __metaclass__ class property or global variable is old syntax from Python 2.x and not longer supported. See also "What's new in Python 3" and PEP 2115.

提交回复
热议问题