1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-11 15:12:44 +00:00

deprecation(python): deprecate @expect

This commit is contained in:
matejcik 2025-01-03 12:28:54 +01:00 committed by matejcik
parent 8b6d8e7572
commit 0cae2ab2d0
2 changed files with 13 additions and 3 deletions

View File

@ -0,0 +1 @@
`@expect` decorator is deprecated -- use `TrezorClient.call(expect=...)` instead.

View File

@ -14,11 +14,14 @@
# You should have received a copy of the License along with this library. # You should have received a copy of the License along with this library.
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. # If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
from __future__ import annotations
import functools import functools
import hashlib import hashlib
import re import re
import struct import struct
import unicodedata import unicodedata
import warnings
from typing import ( from typing import (
TYPE_CHECKING, TYPE_CHECKING,
Any, Any,
@ -279,10 +282,16 @@ def expect(
ret_type: "Optional[Type[R]]" = None, ret_type: "Optional[Type[R]]" = None,
) -> "Callable[[Callable[P, MessageType]], Callable[P, Union[MT, R]]]": ) -> "Callable[[Callable[P, MessageType]], Callable[P, Union[MT, R]]]":
""" """
Decorator checks if the method Decorator checks if the method returned one of expected protobuf messages or raises
returned one of expected protobuf messages an exception.
or raises an exception
Deprecated. Use `client.call(msg, expect=expected)` instead.
""" """
warnings.warn(
"Use `client.call(msg, expect=expected)` instead",
DeprecationWarning,
stacklevel=2,
)
def decorator(f: "Callable[P, MessageType]") -> "Callable[P, Union[MT, R]]": def decorator(f: "Callable[P, MessageType]") -> "Callable[P, Union[MT, R]]":
@functools.wraps(f) @functools.wraps(f)