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:
docstr, optional

Documentation for the attribute of the class. Default is "".

Added in version 1.2.

copybool, optional

If True the value is deepcopied before setting, otherwise it is saved as reference. Default is True.

Added in version 1.2.

default_factoryCallable[[], Mapping], optional keyword-only

The factory to use to create the default value of the meta attribute. This must be a callable that returns a Mapping object. Default is OrderedDict, creating an empty OrderedDict.

Added in version 6.0.

Examples

MetaData can be used as a descriptor to define a meta attribute`.

>>> class Foo:
...     meta = MetaData()
...     def __init__(self, meta=None):
...         self.meta = meta

Foo can be instantiated with a meta argument.

>>> foo = Foo(meta={'a': 1, 'b': 2})
>>> foo.meta
{'a': 1, 'b': 2}

The default value of meta is an empty OrderedDict. This can be set by passing None to the meta argument.

>>> foo = Foo()
>>> foo.meta
OrderedDict()

If an OrderedDict is not a good default metadata type then the default_factory keyword can be used to set the default to a different Mapping 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 returns None since metadata is on the class’ instances, not the class itself.

>>> print(Foo.meta)
None

Attributes Summary

Attributes Documentation

default_factory#