MetaData#
- class astropy.utils.metadata.MetaData(doc='', copy=True, *, default_factory=<class 'collections.OrderedDict'>)[source]#
Bases:
objectA descriptor for classes that have a
metaproperty.This can be set to any valid
Mapping.- Parameters:
- doc
str, optional Documentation for the attribute of the class. Default is
"".Added in version 1.2.
- copy
bool, optional If
Truethe value is deepcopied before setting, otherwise it is saved as reference. Default isTrue.Added in version 1.2.
- default_factory
Callable[[],Mapping], optional keyword-only The factory to use to create the default value of the
metaattribute. This must be a callable that returns aMappingobject. Default isOrderedDict, creating an emptyOrderedDict.Added in version 6.0.
- doc
Examples
MetaDatacan be used as a descriptor to define ametaattribute`.>>> class Foo: ... meta = MetaData() ... def __init__(self, meta=None): ... self.meta = meta
Foocan be instantiated with ametaargument.>>> foo = Foo(meta={'a': 1, 'b': 2}) >>> foo.meta {'a': 1, 'b': 2}
The default value of
metais an emptyOrderedDict. This can be set by passingNoneto themetaargument.>>> foo = Foo() >>> foo.meta OrderedDict()
If an
OrderedDictis not a good default metadata type then thedefault_factorykeyword can be used to set the default to a differentMappingtype, when the class is defined.’>>> class Bar: ... meta = MetaData(default_factory=dict) ... def __init__(self, meta=None): ... self.meta = meta
>>> Bar().meta {}
When accessed from the class
.metareturnsNonesince metadata is on the class’ instances, not the class itself.>>> print(Foo.meta) None
Attributes Summary
Attributes Documentation
- default_factory#