def record(*fields):
"""Constructs a type that can be extended to create immutable, value types.
Examples:
A typical declaration looks like::
class MyRecord(record('a', ('b', 1))):
pass
The above would make a sub-class of ``collections.namedtuple`` that was named ``MyRecord`` with
a constructor that had the ``b`` field set to 1 by default.
Note:
This uses meta-class machinery to rewrite the inheritance hierarchy.
This is done in order to make sure that the underlying ``namedtuple`` instance is
bound to the right type name and to make sure that the synthetic class that is generated
to enable this machinery is not enabled for sub-classes of a user's record class.
Args:
fields (list[str | (str, any)]): A sequence of str or pairs that
"""
@six.add_metaclass(_RecordMetaClass)
class RecordType(object):
_record_sentinel = True
_record_fields = fields
return RecordType
评论列表
文章目录