MCPcopy Create free account
hub / github.com/dask/dask / _deprecated

Function _deprecated

dask/utils.py:84–144  ·  view source on GitHub ↗

Decorator to mark a function as deprecated Parameters ---------- version : str, optional Version of Dask in which the function was deprecated. If specified, the version will be included in the default warning message. This should no longer be used after the intro

(
    *,
    version: str | None = None,
    after_version: str | None = None,
    message: str | None = None,
    use_instead: str | None = None,
    category: type[Warning] = FutureWarning,
)

Source from the content-addressed store, hash-verified

82
83
84def _deprecated(
85 *,
86 version: str | None = None,
87 after_version: str | None = None,
88 message: str | None = None,
89 use_instead: str | None = None,
90 category: type[Warning] = FutureWarning,
91):
92 """Decorator to mark a function as deprecated
93
94 Parameters
95 ----------
96 version : str, optional
97 Version of Dask in which the function was deprecated. If specified, the version
98 will be included in the default warning message. This should no longer be used
99 after the introduction of automated versioning system.
100 after_version : str, optional
101 Version of Dask after which the function was deprecated. If specified, the
102 version will be included in the default warning message.
103 message : str, optional
104 Custom warning message to raise.
105 use_instead : str, optional
106 Name of function to use in place of the deprecated function.
107 If specified, this will be included in the default warning
108 message.
109 category : type[Warning], optional
110 Type of warning to raise. Defaults to ``FutureWarning``.
111
112 Examples
113 --------
114
115 >>> from dask.utils import _deprecated
116 >>> @_deprecated(after_version="X.Y.Z", use_instead="bar")
117 ... def foo():
118 ... return "baz"
119 """
120
121 def decorator(func):
122 if message is None:
123 msg = f"{func.__name__} "
124 if after_version is not None:
125 msg += f"was deprecated after version {after_version} "
126 elif version is not None:
127 msg += f"was deprecated in version {version} "
128 else:
129 msg += "is deprecated "
130 msg += "and will be removed in a future release."
131
132 if use_instead is not None:
133 msg += f" Please use {use_instead} instead."
134 else:
135 msg = message
136
137 @functools.wraps(func)
138 def wrapper(*args, **kwargs):
139 warnings.warn(msg, category=category, stacklevel=2)
140 return func(*args, **kwargs)
141

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected