I want to know how the __new__
function of type works, how can it create a class using the attr parameters.
for Example:
class ModelMetaclass(type):
def __new__(cls, name, bases, attrs):
return type.__new__(cls, name, bases, attrs)
class User(Model):
__metaclass__ = ModelMetaclass
id = StringField(primary_key=True, ddl='varchar(50)')
email = StringField(ddl='varchar(50)')
password = StringField(ddl='varchar(50)')
class StringField(Field):
def __init__(self, **kw):
self.name = kw.get('name', None)
self.primary_key = kw.get('primary_key', False)
self.ddl= kw.get('ddl', '')
Then, you can use User class like this: u = User(id=10190, name='Michael', email='orm@db.org') print type(u.id)
So, how does the __new__
function translate StringField into str ?