def METHOD_NAME(
    obj: TrezorConnection, *args: "P.args", **kwargs: "P.kwargs"
) -> "R":
    with obj.client_context() as client:
        session_was_resumed = obj.session_id == client.session_id
        if not session_was_resumed and obj.session_id is not None:
            # tried to resume but failed
            click.echo("Warning: failed to resume session.", err=True)
        try:
            return func(client, *args, **kwargs)
        finally:
            if not session_was_resumed:
                try:
                    client.end_session()
                except Exception:
                    pass