Neuroimaging in Python — NiBabel 5.4.0.dev1+g3b1c7b37 documentation (original) (raw)
deprecated
¶
Module to help with deprecating objects and classes
FutureWarningMixin(*args, **kwargs) | Insert FutureWarning for object creation |
---|---|
ModuleProxy(module_name) | Proxy for module that may not yet have been imported |
VisibleDeprecationWarning | Deprecation warning that will be shown by default |
alert_future_error(msg, version, *[, ...]) | Warn or error with appropriate messages for changing functionality. |
FutureWarningMixin¶
class nibabel.deprecated.FutureWarningMixin(*args: P.args, **kwargs: P.kwargs)¶
Bases: object
Insert FutureWarning for object creation
Examples
class C: pass class D(FutureWarningMixin, C): ... warn_message = "Please, don't use this class"
Record the warning
with warnings.catch_warnings(record=True) as warns: ... d = D() ... warns[0].message.args[0] "Please, don't use this class"
__init__(*args: P.args, **kwargs: P.kwargs) → None¶
warn_message = 'This class will be removed in future versions'¶
ModuleProxy¶
class nibabel.deprecated.ModuleProxy(module_name: str)¶
Bases: object
Proxy for module that may not yet have been imported
Parameters:
module_namestr
Full module name e.g. nibabel.minc
Examples
::
arr = np.arange(24).reshape((2, 3, 4)) nifti1 = ModuleProxy(‘nibabel.nifti1’) nifti1_image = nifti1.Nifti1Image(arr, np.eye(4))
So, the nifti1
object is a proxy that will import the required module when you do attribute access and return the attributes of the imported module.
__init__(module_name: str) → None¶
VisibleDeprecationWarning¶
class nibabel.deprecated.VisibleDeprecationWarning¶
Bases: UserWarning
Deprecation warning that will be shown by default
Python >= 2.7 does not show standard DeprecationWarnings by default:
http://docs.python.org/dev/whatsnew/2.7.html#the-future-for-python-2-x
Use this class for cases where we do want to show deprecations by default.
__init__(*args, **kwargs)¶
alert_future_error¶
nibabel.deprecated.alert_future_error(msg: str, version: str, *, warning_class: type[Warning] = <class 'FutureWarning'>, error_class: type[Exception] = <class 'RuntimeError'>, warning_rec: str = '', error_rec: str = '', stacklevel: int = 2) → None¶
Warn or error with appropriate messages for changing functionality.
Parameters:
msgstr
Description of the condition that led to the alert
versionstr
NiBabel version at which the warning will become an error
warning_classsubclass of Warning, optional
Warning class to emit before version
error_classsubclass of Exception, optional
Error class to emit after version
warning_recstr, optional
Guidance for suppressing the warning and avoiding the future error
error_rec: str, optional
Guidance for resolving the error
stacklevel: int, optional
Warnings stacklevel to provide; note that this will be incremented by 1, so provide the stacklevel you would provide directly to warnings.warn()