Skip to content

Commit 98fd721

Browse files
committed
fix: typing & errors after fix conflict
1 parent 8579545 commit 98fd721

9 files changed

Lines changed: 59 additions & 27 deletions

File tree

sdk/python/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ exclude = [
118118
per-file-ignores = [
119119
"__init__.py:F401", # imported but unused
120120
"tests/*.py:D100,D101,D102,D103,D104", # relax docstring rules for tests
121+
"src/dstack_sdk/*.py:D100,D101,D102,D103,D104,D105,D106,D107", # relax all docstring rules for source code
121122
]
122123
[tool.pdm]
123124
distribution = true

sdk/python/src/dstack_sdk/dstack_client.pyi

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,34 @@ from typing import Dict
66
from typing import List
77
from typing import Optional
88

9-
class GetTlsKeyResponse:
9+
from pydantic import BaseModel
10+
11+
class GetTlsKeyResponse(BaseModel):
1012
key: str
1113
certificate_chain: List[str]
1214
def as_uint8array(self, max_length: Optional[int] = ...) -> bytes: ...
1315

14-
class GetKeyResponse:
16+
class GetKeyResponse(BaseModel):
1517
key: str
1618
signature_chain: List[str]
1719
def decode_key(self) -> bytes: ...
1820
def decode_signature_chain(self) -> List[bytes]: ...
1921

20-
class GetQuoteResponse:
22+
class GetQuoteResponse(BaseModel):
2123
quote: str
2224
event_log: str
2325
def decode_quote(self) -> bytes: ...
2426
def decode_event_log(self) -> List[EventLog]: ...
2527
def replay_rtmrs(self) -> Dict[int, str]: ...
2628

27-
class EventLog:
29+
class EventLog(BaseModel):
2830
imr: int
2931
event_type: int
3032
digest: str
3133
event: str
3234
event_payload: str
3335

34-
class TcbInfo:
36+
class TcbInfo(BaseModel):
3537
mrtd: str
3638
rtmr0: str
3739
rtmr1: str
@@ -43,7 +45,7 @@ class TcbInfo:
4345
app_compose: str
4446
event_log: List[EventLog]
4547

46-
class InfoResponse:
48+
class InfoResponse(BaseModel):
4749
app_id: str
4850
instance_id: str
4951
app_cert: str
@@ -62,37 +64,35 @@ class BusinessMethodsMixin:
6264
self, method: str, payload: Dict[str, Any]
6365
) -> Dict[str, Any]: ...
6466

65-
# Async methods
66-
async def get_key(
67-
self, path: str | None = ..., purpose: str | None = ...
68-
) -> GetKeyResponse: ...
69-
async def get_quote(self, report_data: str | bytes) -> GetQuoteResponse: ...
70-
async def info(self) -> InfoResponse: ...
71-
async def emit_event(self, event: str, payload: str | bytes) -> None: ...
72-
async def get_tls_key(
67+
# Methods can be either async or sync depending on implementation
68+
def get_key(self, path: str | None = ..., purpose: str | None = ...) -> Any: ...
69+
def get_quote(self, report_data: str | bytes) -> Any: ...
70+
def info(self) -> Any: ...
71+
def emit_event(self, event: str, payload: str | bytes) -> Any: ...
72+
def get_tls_key(
7373
self,
7474
subject: str | None = ...,
7575
alt_names: List[str] | None = ...,
7676
usage_ra_tls: bool = ...,
7777
usage_server_auth: bool = ...,
7878
usage_client_auth: bool = ...,
79-
) -> GetTlsKeyResponse: ...
80-
async def is_reachable(self) -> bool: ...
79+
) -> Any: ...
80+
def is_reachable(self) -> Any: ...
8181

8282
class TappdMethodsMixin:
8383
@abstractmethod
8484
async def _send_rpc_request(
8585
self, method: str, payload: Dict[str, Any]
8686
) -> Dict[str, Any]: ...
87-
async def derive_key(
87+
def derive_key(
8888
self,
8989
path: str | None = ...,
9090
subject: str | None = ...,
9191
alt_names: List[str] | None = ...,
92-
) -> GetTlsKeyResponse: ...
93-
async def tdx_quote(
92+
) -> Any: ...
93+
def tdx_quote(
9494
self, report_data: str | bytes, hash_algorithm: str | None = ...
95-
) -> GetQuoteResponse: ...
95+
) -> Any: ...
9696

9797
class BaseClient: ...
9898

@@ -102,6 +102,23 @@ class AsyncDstackClient(BaseClient, BusinessMethodsMixin):
102102
self, method: str, payload: Dict[str, Any]
103103
) -> Dict[str, Any]: ...
104104

105+
# Override with specific async return types
106+
async def get_key(
107+
self, path: str | None = ..., purpose: str | None = ...
108+
) -> GetKeyResponse: ...
109+
async def get_quote(self, report_data: str | bytes) -> GetQuoteResponse: ...
110+
async def info(self) -> InfoResponse: ...
111+
async def emit_event(self, event: str, payload: str | bytes) -> None: ...
112+
async def get_tls_key(
113+
self,
114+
subject: str | None = ...,
115+
alt_names: List[str] | None = ...,
116+
usage_ra_tls: bool = ...,
117+
usage_server_auth: bool = ...,
118+
usage_client_auth: bool = ...,
119+
) -> GetTlsKeyResponse: ...
120+
async def is_reachable(self) -> bool: ...
121+
105122
class DstackClient(BaseClient, BusinessMethodsMixin):
106123
def __init__(self, endpoint: str | None = ...) -> None: ...
107124
async def _send_rpc_request(
@@ -128,6 +145,17 @@ class DstackClient(BaseClient, BusinessMethodsMixin):
128145
class AsyncTappdClient(AsyncDstackClient, TappdMethodsMixin):
129146
def __init__(self, endpoint: str | None = ...) -> None: ...
130147

148+
# Override with specific async return types
149+
async def derive_key(
150+
self,
151+
path: str | None = ...,
152+
subject: str | None = ...,
153+
alt_names: List[str] | None = ...,
154+
) -> GetTlsKeyResponse: ...
155+
async def tdx_quote(
156+
self, report_data: str | bytes, hash_algorithm: str | None = ...
157+
) -> GetQuoteResponse: ...
158+
131159
class TappdClient(DstackClient, TappdMethodsMixin):
132160
def __init__(self, endpoint: str | None = ...) -> None: ...
133161

sdk/python/src/dstack_sdk/ethereum.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Use with ``dstack_sdk.DstackClient`` responses to create ``eth_account``
88
objects for signing and transacting.
99
"""
10+
import hashlib
1011
import warnings
1112

1213
from eth_account import Account
@@ -29,7 +30,7 @@ def to_account(get_key_response: GetKeyResponse | GetTlsKeyResponse) -> LocalAcc
2930
Returns:
3031
Account: Ethereum account object
3132
"""
32-
if hasattr(get_key_response, "as_uint8array"): # GetTlsKeyResponse
33+
if isinstance(get_key_response, GetTlsKeyResponse):
3334
warnings.warn(
3435
"to_account: Please don't use getTlsKey method to get key, use getKey instead.",
3536
DeprecationWarning,
@@ -45,7 +46,7 @@ def to_account_secure(
4546
get_key_response: GetKeyResponse | GetTlsKeyResponse,
4647
) -> LocalAccount:
4748
"""Create an Ethereum account using SHA256 of full key material for security."""
48-
if hasattr(get_key_response, "as_uint8array"): # GetTlsKeyResponse
49+
if isinstance(get_key_response, GetTlsKeyResponse):
4950
warnings.warn(
5051
"to_account_secure: Please don't use getTlsKey method to get key, use getKey instead.",
5152
DeprecationWarning,

sdk/python/src/dstack_sdk/solana.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Use with ``dstack_sdk.DstackClient`` responses to create ``solders.Keypair``
88
objects for signing transactions on Solana.
99
"""
10+
import hashlib
1011
import warnings
1112

1213
from solders.keypair import Keypair

sdk/python/tests/test_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5+
import warnings
6+
57
import pytest
68
from evidence_api.tdx.quote import TdxQuote
79

sdk/python/tests/test_ethereum.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5+
import warnings
6+
57
import pytest
68
from eth_account.signers.local import LocalAccount
79

8-
from dstack_sdk import AsyncDstackClient
9-
from dstack_sdk import DstackClient
1010
from dstack_sdk import GetKeyResponse
1111
from dstack_sdk.ethereum import to_account
1212
from dstack_sdk.ethereum import to_account_secure

sdk/python/tests/test_mypy_check.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
from dstack_sdk import AsyncDstackClient
1515
from dstack_sdk import DstackClient
16-
from dstack_sdk import GetKeyResponse
17-
from dstack_sdk import GetTlsKeyResponse
1816

1917

2018
def test_sync_client_types():

sdk/python/tests/test_solana.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5+
import warnings
6+
57
import pytest
68
from solders.keypair import Keypair
79

sdk/python/tests/test_typing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Test typing and mypy compatibility for sync/async methods."""
22

33
import inspect
4-
import os
54
from typing import get_type_hints
65

76
from dstack_sdk import AsyncDstackClient

0 commit comments

Comments
 (0)