Odoo 9字段初始化过程

时间:2018-09-05 13:02:29

标签: python odoo

在Odoo 9.0类MetaField方法__init__()中,为什么dir(cls)结果包含“参数”?

class MetaField(type):
    # ...

    def __init__(cls, name, bases, attrs):
    # ...
    for attr in dir(cls):
        if attr.startswith('_column_'):
            cls.column_attrs.append((attr[8:], attr))
        elif attr.startswith('_related_'):
            cls.related_attrs.append((attr[9:], attr))
        elif attr.startswith('_description_'):
            cls.description_attrs.append((attr[13:], attr))

dir(cls)结果:

[...'_setup_related_full', '_slots', 'args', 'automatic', 'base_field'...]

我只能在Field.args中找到__init__()声明,它会让args进入dir()吗?

class Field(object):
    # ...

    def __init__(self, string=None, **kwargs):
        kwargs['string'] = string
        args = {key: val for key, val in kwargs.iteritems() if val is not None}
        self.args = args or EMPTY_DICT
        self._setup_done = None

0 个答案:

没有答案