{ } Raw JSON

bundles / astropy latest / astropy / utils / decorators / deprecated_attribute

function

astropy.utils.decorators:deprecated_attribute

source: /astropy/utils/decorators.py :239

Signature

def   deprecated_attribute ( name since message = None alternative = None pending = False warning_type = <class 'astropy.utils.exceptions.AstropyDeprecationWarning'> pending_warning_type = <class 'astropy.utils.exceptions.AstropyPendingDeprecationWarning'> )

Summary

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, and alternative 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.

pending : bool, optional

If True, uses a AstropyPendingDeprecationWarning instead of warning_type.

warning_type : Warning

Warning to be issued. Default is AstropyDeprecationWarning.

pending_warning_type : Warning

Pending warning to be issued. This only works if pending is set to True. Default is AstropyPendingDeprecationWarning.

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

Aliases

  • astropy.utils.deprecated_attribute