Manipulating class variables
In this section, we will take an example to look at manipulating class variables further using metaclasses. We will be creating a metaclass named SchemaMetaClass
and will define the __new__
method to manipulate attributes of a class if they are variables of data types that belong to integer
, float
, string
, or boolean
. Let’s go through the steps real quick:
- We will now create the
SchemaMetaClass
with the parent class as type and have modified thenew
method to check the following conditions:class SchemaMetaClass(type):
- Create the dictionary object
newattributes
. If theclass
attribute is a built-inclass
method that starts with__
, then the attribute’s value is stored as such innewattributes
:def __new__(classitself, classname, baseclasses, attributes): &...