diff options
| author | shumkovnd <[email protected]> | 2023-11-10 14:39:34 +0300 | 
|---|---|---|
| committer | shumkovnd <[email protected]> | 2023-11-10 16:42:24 +0300 | 
| commit | 77eb2d3fdcec5c978c64e025ced2764c57c00285 (patch) | |
| tree | c51edb0748ca8d4a08d7c7323312c27ba1a8b79a /contrib/python/Pillow/py3/PIL/_deprecate.py | |
| parent | dd6d20cadb65582270ac23f4b3b14ae189704b9d (diff) | |
KIKIMR-19287: add task_stats_drawing script
Diffstat (limited to 'contrib/python/Pillow/py3/PIL/_deprecate.py')
| -rw-r--r-- | contrib/python/Pillow/py3/PIL/_deprecate.py | 69 | 
1 files changed, 69 insertions, 0 deletions
diff --git a/contrib/python/Pillow/py3/PIL/_deprecate.py b/contrib/python/Pillow/py3/PIL/_deprecate.py new file mode 100644 index 00000000000..2f2a3df13e3 --- /dev/null +++ b/contrib/python/Pillow/py3/PIL/_deprecate.py @@ -0,0 +1,69 @@ +from __future__ import annotations + +import warnings + +from . import __version__ + + +def deprecate( +    deprecated: str, +    when: int | None, +    replacement: str | None = None, +    *, +    action: str | None = None, +    plural: bool = False, +) -> None: +    """ +    Deprecations helper. + +    :param deprecated: Name of thing to be deprecated. +    :param when: Pillow major version to be removed in. +    :param replacement: Name of replacement. +    :param action: Instead of "replacement", give a custom call to action +        e.g. "Upgrade to new thing". +    :param plural: if the deprecated thing is plural, needing "are" instead of "is". + +    Usually of the form: + +        "[deprecated] is deprecated and will be removed in Pillow [when] (yyyy-mm-dd). +        Use [replacement] instead." + +    You can leave out the replacement sentence: + +        "[deprecated] is deprecated and will be removed in Pillow [when] (yyyy-mm-dd)" + +    Or with another call to action: + +        "[deprecated] is deprecated and will be removed in Pillow [when] (yyyy-mm-dd). +        [action]." +    """ + +    is_ = "are" if plural else "is" + +    if when is None: +        removed = "a future version" +    elif when <= int(__version__.split(".")[0]): +        msg = f"{deprecated} {is_} deprecated and should be removed." +        raise RuntimeError(msg) +    elif when == 11: +        removed = "Pillow 11 (2024-10-15)" +    else: +        msg = f"Unknown removal version: {when}. Update {__name__}?" +        raise ValueError(msg) + +    if replacement and action: +        msg = "Use only one of 'replacement' and 'action'" +        raise ValueError(msg) + +    if replacement: +        action = f". Use {replacement} instead." +    elif action: +        action = f". {action.rstrip('.')}." +    else: +        action = "" + +    warnings.warn( +        f"{deprecated} {is_} deprecated and will be removed in {removed}{action}", +        DeprecationWarning, +        stacklevel=3, +    )  | 
