-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 !!

Ciasto piekarz
  • 7,853
  • 18
  • 101
  • 197

1 Answers1

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/

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
securecurve
  • 5,589
  • 5
  • 45
  • 80