22 import deprecated.sphinx
27 from contextlib
import contextmanager
31 """Deprecate a pybind11-wrapped C++ interface function, method or class. 33 This needs to use a pass-through Python wrapper so that 34 `~deprecated.sphinx.deprecated` can update its docstring; pybind11 35 docstrings are native and cannot be modified. 37 Note that this is not a decorator; its output must be assigned to 38 replace the method being deprecated. 42 obj : function, method, or class 43 The function, method, or class to deprecate. 45 Reason for deprecation, passed to `~deprecated.sphinx.deprecated` 47 Warning category, passed to `~deprecated.sphinx.deprecated` 51 obj : function, method, or class 52 Wrapped function, method, or class 56 .. code-block:: python 58 ExposureF.getCalib = deprecate_pybind11(ExposureF.getCalib, 59 reason="Replaced by getPhotoCalib. (Will be removed in 18.0)", 60 category=FutureWarning)) 64 def internal(*args, **kwargs):
65 return obj(*args, **kwargs)
67 return deprecated.sphinx.deprecated(reason=reason, category=category)(internal)
72 """Suppress warnings generated by `deprecated.sphinx.deprecated`. 74 Naively, one might attempt to suppress these warnings by using 75 `~warnings.catch_warnings`. However, `~deprecated.sphinx.deprecated` 76 attempts to install its own filter, overriding that. This convenience 77 method works around this and properly suppresses the warnings by providing 78 a mock `~warnings.simplefilter` for `~deprecated.sphinx.deprecated` to 83 category : `Warning` or subclass 84 The category of warning to suppress. 86 with warnings.catch_warnings():
87 warnings.simplefilter(
"ignore", category)
88 with unittest.mock.patch.object(warnings,
"simplefilter"):
def suppress_deprecations(category=FutureWarning)
def deprecate_pybind11(obj, reason, category=FutureWarning)