astropy.utils.decorators.deprecated_attribute(name, since, message=None, alternative=None, pending=False, warning_type=<class 'astropy.utils.exceptions.AstropyDeprecationWarning'>)[source]#

Used to mark a public attribute as deprecated. This creates a property that will warn when the given attribute name is accessed. To prevent the warning (i.e. for internal code), use the private name for the attribute by prepending an underscore (i.e. self._name), or set an alternative explicitly.


The name of the deprecated attribute.


The release at which this API became deprecated. This is required.

messagestr, optional

Override the default deprecation message. The format specifier name may be used for the name of the attribute, and alternative may be used in the deprecation message to insert the name of an alternative to the deprecated function.

alternativestr, optional

An alternative attribute that the user may use in place of the deprecated attribute. The deprecation warning will tell the user about this alternative if provided.

pendingbool, optional

If True, uses a AstropyPendingDeprecationWarning instead of warning_type.


Warning to be issued. Default is AstropyDeprecationWarning.


class MyClass:
    # Mark the old_name as deprecated
    old_name = deprecated_attribute("old_name", "0.1")

    def method(self):
        self._old_name = 42

class MyClass2:
    old_name = deprecated_attribute(
        "old_name", "1.2", alternative="new_name"

    def method(self):
        self.new_name = 24