Skip to content

Commit

Permalink
feat: adds deprecate function
Browse files Browse the repository at this point in the history
This wrapper format seems to satisfy `pyright` enough to trigger a strikethrough
  • Loading branch information
dangotbanned committed Jul 1, 2024
1 parent 2505ce2 commit fe1917e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions altair/utils/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,48 @@ def __call__(self, arg: _T, /) -> _T:
return super().__call__(arg)


# NOTE: Annotating the return type breaks `pyright` detecting [reportDeprecated]
def deprecate(
*,
version: te.LiteralString,
alternative: te.LiteralString | None = None,
message: te.LiteralString | None = None,
category: type[AltairDeprecationWarning] | None = AltairDeprecationWarning,
stacklevel: int = 1,
):
"""Indicate that a class, function or overload is deprecated.
When this decorator is applied to an object, the type checker
will generate a diagnostic on usage of the deprecated object.
Parameters
----------
version
``altair`` version the deprecation first appeared.
alternative
Suggested replacement class/method/function.
message
Additional message appended to ``version``, ``alternative``.
category
If the *category* is ``None``, no warning is emitted at runtime.
stacklevel
The *stacklevel* determines where the
warning is emitted. If it is ``1`` (the default), the warning
is emitted at the direct caller of the deprecated object; if it
is higher, it is emitted further up the stack.
Static type checker behavior is not affected by the *category*
and *stacklevel* arguments.
"""
output = f"Deprecated in `altair={version}`."
if alternative:
output = f"{output} Use {alternative} instead."
return te.deprecated(
f"{output}\n\n{message}" if message else output,
category=category,
stacklevel=stacklevel,
)


def msg(
*,
version: te.LiteralString,
Expand Down
2 changes: 1 addition & 1 deletion altair/vegalite/v5/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ def selection_multi(**kwargs):
return _selection(type="point", **kwargs)


@utils.deprecation.deprecated("", version="5.0.0", alternative="selection_point")
@utils.deprecation.deprecate(version="5.0.0", alternative="selection_point")
def selection_single(**kwargs):
"""'selection_single' is deprecated. Use 'selection_point'"""
return _selection(type="point", **kwargs)
Expand Down

0 comments on commit fe1917e

Please sign in to comment.