|
29 | 29 | import asyncio |
30 | 30 | import collections.abc |
31 | 31 | import datetime |
32 | | -import functools |
33 | 32 | import json |
34 | 33 | import re |
35 | 34 | import sys |
36 | 35 | import types |
37 | | -import warnings |
38 | 36 | from bisect import bisect_left |
39 | 37 | from enum import Enum, auto |
40 | 38 | from inspect import isawaitable as _isawaitable |
|
73 | 71 |
|
74 | 72 |
|
75 | 73 | __all__ = ( |
76 | | - "warn_deprecated", |
77 | | - "deprecated", |
78 | 74 | "oauth_url", |
79 | 75 | "snowflake_time", |
80 | 76 | "find", |
@@ -240,102 +236,6 @@ def decorator(overridden: T) -> T: |
240 | 236 | return decorator |
241 | 237 |
|
242 | 238 |
|
243 | | -def warn_deprecated( |
244 | | - name: str, |
245 | | - instead: str | None = None, |
246 | | - since: str | None = None, |
247 | | - removed: str | None = None, |
248 | | - reference: str | None = None, |
249 | | - stacklevel: int = 3, |
250 | | -) -> None: |
251 | | - """Warn about a deprecated function, with the ability to specify details about the deprecation. Emits a |
252 | | - DeprecationWarning. |
253 | | -
|
254 | | - Parameters |
255 | | - ---------- |
256 | | - name: str |
257 | | - The name of the deprecated function. |
258 | | - instead: Optional[:class:`str`] |
259 | | - A recommended alternative to the function. |
260 | | - since: Optional[:class:`str`] |
261 | | - The version in which the function was deprecated. This should be in the format ``major.minor(.patch)``, where |
262 | | - the patch version is optional. |
263 | | - removed: Optional[:class:`str`] |
264 | | - The version in which the function is planned to be removed. This should be in the format |
265 | | - ``major.minor(.patch)``, where the patch version is optional. |
266 | | - reference: Optional[:class:`str`] |
267 | | - A reference that explains the deprecation, typically a URL to a page such as a changelog entry or a GitHub |
268 | | - issue/PR. |
269 | | - stacklevel: :class:`int` |
270 | | - The stacklevel kwarg passed to :func:`warnings.warn`. Defaults to 3. |
271 | | - """ |
272 | | - warnings.simplefilter("always", DeprecationWarning) # turn off filter |
273 | | - message = f"{name} is deprecated" |
274 | | - if since: |
275 | | - message += f" since version {since}" |
276 | | - if removed: |
277 | | - message += f" and will be removed in version {removed}" |
278 | | - if instead: |
279 | | - message += f", consider using {instead} instead" |
280 | | - message += "." |
281 | | - if reference: |
282 | | - message += f" See {reference} for more information." |
283 | | - |
284 | | - warnings.warn(message, stacklevel=stacklevel, category=DeprecationWarning) |
285 | | - warnings.simplefilter("default", DeprecationWarning) # reset filter |
286 | | - |
287 | | - |
288 | | -def deprecated( |
289 | | - instead: str | None = None, |
290 | | - since: str | None = None, |
291 | | - removed: str | None = None, |
292 | | - reference: str | None = None, |
293 | | - stacklevel: int = 3, |
294 | | - *, |
295 | | - use_qualname: bool = True, |
296 | | -) -> Callable[[Callable[[P], T]], Callable[[P], T]]: |
297 | | - """A decorator implementation of :func:`warn_deprecated`. This will automatically call :func:`warn_deprecated` when |
298 | | - the decorated function is called. |
299 | | -
|
300 | | - Parameters |
301 | | - ---------- |
302 | | - instead: Optional[:class:`str`] |
303 | | - A recommended alternative to the function. |
304 | | - since: Optional[:class:`str`] |
305 | | - The version in which the function was deprecated. This should be in the format ``major.minor(.patch)``, where |
306 | | - the patch version is optional. |
307 | | - removed: Optional[:class:`str`] |
308 | | - The version in which the function is planned to be removed. This should be in the format |
309 | | - ``major.minor(.patch)``, where the patch version is optional. |
310 | | - reference: Optional[:class:`str`] |
311 | | - A reference that explains the deprecation, typically a URL to a page such as a changelog entry or a GitHub |
312 | | - issue/PR. |
313 | | - stacklevel: :class:`int` |
314 | | - The stacklevel kwarg passed to :func:`warnings.warn`. Defaults to 3. |
315 | | - use_qualname: :class:`bool` |
316 | | - Whether to use the qualified name of the function in the deprecation warning. If ``False``, the short name of |
317 | | - the function will be used instead. For example, __qualname__ will display as ``Client.login`` while __name__ |
318 | | - will display as ``login``. Defaults to ``True``. |
319 | | - """ |
320 | | - |
321 | | - def actual_decorator(func: Callable[[P], T]) -> Callable[[P], T]: |
322 | | - @functools.wraps(func) |
323 | | - def decorated(*args: P.args, **kwargs: P.kwargs) -> T: |
324 | | - warn_deprecated( |
325 | | - name=func.__qualname__ if use_qualname else func.__name__, |
326 | | - instead=instead, |
327 | | - since=since, |
328 | | - removed=removed, |
329 | | - reference=reference, |
330 | | - stacklevel=stacklevel, |
331 | | - ) |
332 | | - return func(*args, **kwargs) |
333 | | - |
334 | | - return decorated |
335 | | - |
336 | | - return actual_decorator |
337 | | - |
338 | | - |
339 | 239 | def oauth_url( |
340 | 240 | client_id: int | str, |
341 | 241 | *, |
|
0 commit comments