deprecated_attribute#
- 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.- Parameters:
- name
str
The name of the deprecated attribute.
- since
str
The release at which this API became deprecated. This is required.
- message
str
, optional Override the default deprecation message. The format specifier
name
may be used for the name of the attribute, andalternative
may be used in the deprecation message to insert the name of an alternative to the deprecated function.- alternative
str
, 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_type
Warning
Warning to be issued. Default is
AstropyDeprecationWarning
.
- name
Examples
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