-1

Example of setting metaclass to LoggingType i spotted at my workplace.

import logging as _logging class SomeClass(object): __metaclass__ = _logging.LoggingType 

Here is the example I have seen for ABCMeta set to __metaclass__

I want to know the practical advantage if their is any example of setting ABCMeta as metaclass as shown below: from the docs

from abc import ABCMeta class MyABC: __metaclass__ = ABCMeta 

to me my question sounds like how to take advantage of

 register(subclass) Register subclass as a “virtual subclass” 

How can we benefit from it ?

If you find my question is repeated please link this post up !!

0

1 Answer 1

0

Abstract base classes are a form of interface checking more strict than individual hasattr() checks for particular methods. By defining an abstract base class, you can define a common API for a set of subclasses. This capability is especially useful in situations where a third-party is going to provide implementations, such as with plugins to an application, but can also aid you when working on a large team or with a large code-base where keeping all classes in your head at the same time is difficult or not possible.

Reference: http://pymotw.com/2/abc/

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.