Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of python metaclass conflict

Shulou Source: shulou.com Published: 2022-06-03 09:21:21 10月03日 Update

This article mainly shows you the "sample analysis of python metaclass conflicts", which is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn the article "sample analysis of python metaclass conflicts".

1. When multiple subclasses inherit, an error occurs when multiple parent classes have different metaclasses.

2. All metaclasses involved in multiple parent classes have inheritance relationships.

3. Build a metaclass and inherit all the metaclasses involved in the parent class.

Example

Class Meta1 (type): def _ new__ (mcs, * args, * * kwargs): return super (Meta1, mcs). _ _ new__ (mcs, * args, * * kwargs) # change part: Meta2 inherits Meta1class Meta2 (Meta1): def _ new__ (mcs, * args, * * kwargs): return super (Meta2, mcs). _ _ new__ (mcs, * args) * * kwargs) class Body (metaclass=Meta1): pass class Head (metaclass=Meta2): pass class Human (Body, Head): pass is all the contents of the article "sample Analysis of python Metaclass conflicts" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Examples conflicts analysis content articles between multiple learning help different subcategories examples easy to understand more organization knowledge editing industry information information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Microsoft Docker NVidia Huawei