Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Confidential Ledger] Remove duplicate typing #23441

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eng/tox/mypy_hard_failure_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
"azure-appconfiguration",
"azure-data-tables",
"azure-mixedreality-remoterendering",
"azure-confidentialledger",
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release History

## 1.0.0b2 (2022-03-09)
lynshi marked this conversation as resolved.
Show resolved Hide resolved

- Fixes [[confidentialledger] mypy: function has duplicate type signatures (#23356)](https://github.com/Azure/azure-sdk-for-python/issues/23356)

## 1.0.0b1 (2021-05-12)

- This is the initial release of the Azure Confidential Ledger library.
Original file line number Diff line number Diff line change
Expand Up @@ -362,30 +362,25 @@ def get_transaction_receipt(
interval = kwargs.pop("interval", 0.5)
max_tries = kwargs.pop("max_tries", 6)

ready = False
result = None
state = None
for _ in range(max_tries):
result = self._client.confidential_ledger.get_receipt(
transaction_id=transaction_id,
**kwargs
)

ready = result.state == ConfidentialLedgerQueryState.READY
if not ready:
if result.state is not ConfidentialLedgerQueryState.READY:
state = result.state
time.sleep(interval)
else:
break
if not ready:
raise TimeoutError(
"After {0} attempts, the query still had state {1}, not {2}".format(
max_tries, state, ConfidentialLedgerQueryState.READY
return TransactionReceipt(
transaction_id=result.transaction_id, receipt=result.receipt
)
)

return TransactionReceipt(
transaction_id=result.transaction_id, receipt=result.receipt
raise TimeoutError(
"After {0} attempts, the query still had state {1}, not {2}".format(
max_tries, state, ConfidentialLedgerQueryState.READY
)
)

@distributed_trace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,11 @@
# ------------------------------------

from collections import namedtuple
from typing import Dict, List

from ._enums import LedgerUserRole, TransactionState


try:
from typing import TYPE_CHECKING
except ImportError:
TYPE_CHECKING = False

if TYPE_CHECKING:
# pylint:disable=unused-import
from typing import Dict, List


class AppendResult(namedtuple("AppendResult", ["sub_ledger_id", "transaction_id"])):
"""Result of appending to the ledger.

Expand Down Expand Up @@ -290,10 +281,9 @@ class TransactionReceipt(object):

def __init__(
self,
transaction_id, # type: str
receipt, # type: List[int]
):
# type: (int, List[int]) -> None
transaction_id: str,
receipt: List[int],
) -> None:
lynshi marked this conversation as resolved.
Show resolved Hide resolved
self._transaction_id = transaction_id
self._contents = receipt

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# Licensed under the MIT License.
# ------------------------------------

VERSION = "1.0.0b1"
VERSION = "1.0.0b2"
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
)

if TYPE_CHECKING:
from azure.core.credentials import TokenCredential
from azure.core.credentials_async import AsyncTokenCredential


class ConfidentialLedgerClient(AsyncConfidentialLedgerClientBase):
Expand All @@ -56,7 +56,7 @@ class ConfidentialLedgerClient(AsyncConfidentialLedgerClientBase):
def __init__(
self,
endpoint: str,
credential: Union[ConfidentialLedgerCertificateCredential, "TokenCredential"],
credential: Union[ConfidentialLedgerCertificateCredential, "AsyncTokenCredential"],
ledger_certificate_path: str,
**kwargs: Any,
) -> None:
Expand Down Expand Up @@ -356,30 +356,25 @@ async def get_transaction_receipt(
if transaction_id is None:
raise ValueError("transaction_id cannot be None")

ready = False
result = None
state = None
for _ in range(max_tries):
result = await self._client.confidential_ledger.get_receipt(
transaction_id=transaction_id, **kwargs
)

ready = result.state == ConfidentialLedgerQueryState.READY
if not ready:
if result.state is not ConfidentialLedgerQueryState.READY:
state = result.state
await asyncio.sleep(interval)
else:
break
if not ready:
raise TimeoutError(
"After {} attempts, the query still had state {}, not {}".format(
max_tries, state, ConfidentialLedgerQueryState.READY
return TransactionReceipt(
transaction_id=result.transaction_id, receipt=result.receipt
)
)

return TransactionReceipt(
transaction_id=result.transaction_id, receipt=result.receipt
)
raise TimeoutError(
"After {} attempts, the query still had state {}, not {}".format(
max_tries, state, ConfidentialLedgerQueryState.READY
)
)

@distributed_trace_async
async def get_transaction_status(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
from .._shared import ConfidentialLedgerCertificateCredential, DEFAULT_VERSION

if TYPE_CHECKING:
from azure.core.credentials import TokenCredential
from azure.core.credentials_async import AsyncTokenCredential


class AsyncConfidentialLedgerClientBase(object):
def __init__(
self,
*,
endpoint: str,
credential: Union[ConfidentialLedgerCertificateCredential, "TokenCredential"],
credential: Union[ConfidentialLedgerCertificateCredential, "AsyncTokenCredential"],
ledger_certificate_path: str,
**kwargs: Any
) -> None:
Expand Down