Skip to content

Commit

Permalink
refactor: extract _format_message, add PEP 702 reference
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned committed Jul 3, 2024
1 parent 4e7ee2a commit 4b6699b
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions altair/utils/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@
class AltairDeprecationWarning(DeprecationWarning): ...


def _format_message(
version: LiteralString,
alternative: LiteralString | None,
message: LiteralString | None,
/,
) -> LiteralString:
output = f"Deprecated in `altair={version}`."
if alternative:
output = f"{output} Use {alternative} instead."
return f"{output}\n{message}" if message else output


# NOTE: Annotating the return type breaks `pyright` detecting [reportDeprecated]
# NOTE: `LiteralString` requirement is introduced by stubs
def deprecated(
Expand Down Expand Up @@ -51,12 +63,10 @@ def deprecated(
is higher, it is emitted further up the stack.
Static type checker behavior is not affected by the *category*
and *stacklevel* arguments.
References
----------
[PEP 702](https://peps.python.org/pep-0702/)
"""
output = f"Deprecated in `altair={version}`."
if alternative:
output = f"{output} Use {alternative} instead."
return _deprecated(
f"{output}\n\n{message}" if message else output,
category=category,
stacklevel=stacklevel,
)
msg = _format_message(version, alternative, message)
return _deprecated(msg, category=category, stacklevel=stacklevel)

0 comments on commit 4b6699b

Please sign in to comment.