我正在阅读django的源代码,主要是关于模型。
in class ModelBase code
##########################
def __new__(cls, name, bases, attrs):
super_new = super(ModelBase, cls).__new__
# Also ensure initialization is only performed for subclasses of Model
# (excluding Model class itself).
parents = [b for b in bases if isinstance(b, ModelBase)]
if not parents:
return super_new(cls, name, bases, attrs)
# Create the class.
module = attrs.pop('__module__')
new_class = super_new(cls, name, bases, {'__module__': module})
attr_meta = attrs.pop('Meta', None)
abstract = getattr(attr_meta, 'abstract', False)
if not attr_meta:
meta = getattr(new_class, 'Meta', None)
else:
meta = attr_meta
base_meta = getattr(new_class, '_meta', None)
我很好奇:
base_meta = getattr(new_class, '_meta', None)
由于new_class是由
生成的 new_class = super_new(cls, name, bases, {'__module__': module})
我认为new_class只有属性' 模块',哪里可以得到一个' _meta'属性?
所以实际上我的问题出现在元类中。新,如何在汇编中传递属性?以及如何组合生成的类型实例的属性?"。我做了谷歌工作,我对调用顺序有点了解,但这些细节仍然未知。