From 5173cd3b820eb4ec5e31906927270bcd1424bfbf Mon Sep 17 00:00:00 2001 From: matejcik Date: Tue, 21 Jun 2022 12:02:12 +0200 Subject: [PATCH] fix(python): click 8.1 compatibility fixes #2199 --- python/.changelog.d/2199.fixed | 1 + python/src/trezorlib/cli/trezorctl.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 python/.changelog.d/2199.fixed diff --git a/python/.changelog.d/2199.fixed b/python/.changelog.d/2199.fixed new file mode 100644 index 000000000..a70064110 --- /dev/null +++ b/python/.changelog.d/2199.fixed @@ -0,0 +1 @@ +Add compatibility with Click 8.1 diff --git a/python/src/trezorlib/cli/trezorctl.py b/python/src/trezorlib/cli/trezorctl.py index 8e133d85c..9db6af67f 100755 --- a/python/src/trezorlib/cli/trezorctl.py +++ b/python/src/trezorlib/cli/trezorctl.py @@ -20,7 +20,7 @@ import json import logging import os import time -from typing import TYPE_CHECKING, Any, Iterable, Optional, cast +from typing import TYPE_CHECKING, Any, Callable, Iterable, Optional, TypeVar, cast import click @@ -51,6 +51,8 @@ from . import ( with_client, ) +F = TypeVar("F", bound=Callable) + if TYPE_CHECKING: from ..transport import Transport @@ -121,6 +123,12 @@ class TrezorctlGroup(AliasedGroup): return None + def result_callback(self, replace: bool = False) -> Callable[[F], F]: + """Compatibility wrapper for Click 7.x""" + if hasattr(self, "result_callback"): + return super().result_callback(replace) + return super().resultcallback(replace) # type: ignore [Cannot access member] + def configure_logging(verbose: int) -> None: if verbose: @@ -189,7 +197,7 @@ def cli_main( cli = cast(TrezorctlGroup, cli_main) -@cli.resultcallback() +@cli.result_callback() def print_result(res: Any, is_json: bool, script: bool, **kwargs: Any) -> None: if is_json: if isinstance(res, protobuf.MessageType):