MetaData#
- class astropy.utils.metadata.MetaData(doc='', copy=True, *, default_factory=<class 'collections.OrderedDict'>)[source]#
Bases:
object
A descriptor for classes that have a
meta
property.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
True
the 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
meta
attribute. This must be a callable that returns aMapping
object. Default isOrderedDict
, creating an emptyOrderedDict
.Added in version 6.0.
- doc
Examples
MetaData
can be used as a descriptor to define ameta
attribute`.>>> class Foo: ... meta = MetaData() ... def __init__(self, meta=None): ... self.meta = meta
Foo
can be instantiated with ameta
argument.>>> foo = Foo(meta={'a': 1, 'b': 2}) >>> foo.meta {'a': 1, 'b': 2}
The default value of
meta
is an emptyOrderedDict
. This can be set by passingNone
to themeta
argument.>>> foo = Foo() >>> foo.meta OrderedDict()
If an
OrderedDict
is not a good default metadata type then thedefault_factory
keyword can be used to set the default to a differentMapping
type, 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
.meta
returnsNone
since metadata is on the class’ instances, not the class itself.>>> print(Foo.meta) None
Attributes Summary
Attributes Documentation
- default_factory#