OrderedDescriptor¶
- class astropy.utils.misc.OrderedDescriptor(*args, **kwargs)[source]¶
Bases:
objectDeprecated since version 4.3: The OrderedDescriptor class is deprecated and may be removed in a future version.
You can replace its functionality with a combination of the __init_subclass__ and __set_name__ magic methods introduced in Python 3.6. See https://github.com/astropy/astropy/issues/11094 for recipes on how to replicate their functionality.
Base class for descriptors whose order in the class body should be preserved. Intended for use in concert with the
OrderedDescriptorContainermetaclass.Subclasses of
OrderedDescriptormust define a value for a class attribute called_class_attribute_. This is the name of a class attribute on the container class for these descriptors, which will be set to anOrderedDictat class creation time. ThisOrderedDictwill contain a mapping of all class attributes that were assigned instances of theOrderedDescriptorsubclass, to the instances themselves. See the documentation forOrderedDescriptorContainerfor a concrete example.Optionally, subclasses of
OrderedDescriptormay define a value for a class attribute called_name_attribute_. This should be the name of an attribute on instances of the subclass. When specified, during creation of a class containing these descriptors, the name attribute on each instance will be set to the name of the class attribute it was assigned to on the class.Note
Although this class is intended for use with descriptors (i.e. classes that define any of the
__get__,__set__, or__delete__magic methods), this base class is not itself a descriptor, and technically this could be used for classes that are not descriptors too. However, use with descriptors is the original intended purpose.Deprecated since version 4.3: The OrderedDescriptor class is deprecated and may be removed in a future version.
You can replace its functionality with a combination of the __init_subclass__ and __set_name__ magic methods introduced in Python 3.6. See https://github.com/astropy/astropy/issues/11094 for recipes on how to replicate their functionality.