diff --git a/pylib/anki/decks.py b/pylib/anki/decks.py index 7284af4fe..830e89e83 100644 --- a/pylib/anki/decks.py +++ b/pylib/anki/decks.py @@ -13,7 +13,7 @@ import anki # pylint: disable=unused-import import anki._backend.backend_pb2 as _pb from anki.consts import * from anki.errors import NotFoundError -from anki.utils import from_json_bytes, ids2str, intTime, to_json_bytes +from anki.utils import from_json_bytes, ids2str, intTime, legacy_func, to_json_bytes # public exports DeckTreeNode = _pb.DeckTreeNode @@ -130,6 +130,7 @@ class DeckManager: return deck["id"] + @legacy_func(sub="remove") def rem(self, did: int, cardsToo: bool = True, childrenToo: bool = True) -> None: "Remove the deck. If cardsToo, delete any cards inside." if isinstance(did, str): diff --git a/pylib/anki/utils.py b/pylib/anki/utils.py index 330797c0f..7322f8002 100644 --- a/pylib/anki/utils.py +++ b/pylib/anki/utils.py @@ -18,7 +18,7 @@ import traceback from contextlib import contextmanager from hashlib import sha1 from html.entities import name2codepoint -from typing import Any, Iterable, Iterator, List, Match, Optional, Union +from typing import Any, Callable, Iterable, Iterator, List, Match, Optional, Union from anki.dbproxy import DBProxy @@ -372,3 +372,26 @@ def pointVersion() -> int: from anki.buildinfo import version return int(version.split(".")[-1]) + + +# Legacy support +############################################################################## + + +def legacy_func(sub: Optional[str] = None) -> Callable: + """Print a deprecation warning for the decorated callable recommending the use of + 'sub' instead, if provided. + """ + if sub: + hint = f", use '{sub}' instead" + else: + hint = "" + + def decorater(func: Callable) -> Callable: + def decorated_func(*args: Any, **kwargs: Any) -> Any: + print(f"'{func.__name__}' is deprecated{hint}.") + return func(*args, **kwargs) + + return decorated_func + + return decorater