Custom Meta-Classes

Understand creating custom metaclasses in detail.

In this section, we’ll create a metaclass without type(). To create a custom metaclass we have to inherit type metaclass and override __init__() and __new__().

Overriding the methods

Before overriding the methods, let’s first get an overview on their functionality.

  • __new__: It creates a new object and returns it. Before the control goes to __init__(), __new__() is called.

  • __init__: It initializes the created object.

Example

Let’s code an example.

Get hands-on with 1200+ tech skills courses.