Skip to content

Commit e9e434f

Browse files
authored
Fix: Invalid formatting, flake8 bugs and imports
1 parent b813588 commit e9e434f

File tree

6 files changed

+42
-35
lines changed

6 files changed

+42
-35
lines changed

src/aleph/sdk/client.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import threading
77
import time
88
from datetime import datetime
9+
from io import BytesIO
910
from pathlib import Path
1011
from typing import (
1112
Any,
@@ -23,7 +24,6 @@
2324
TypeVar,
2425
Union,
2526
)
26-
from io import BytesIO
2727

2828
import aiohttp
2929
from aleph_message.models import (
@@ -45,17 +45,18 @@
4545
)
4646
from aleph_message.models.execution.base import Encoding
4747
from aleph_message.status import MessageStatus
48-
from pydantic import ValidationError, BaseModel
48+
from pydantic import ValidationError
4949

5050
from aleph.sdk.types import Account, GenericMessage, StorageEnum
51-
from aleph.sdk.utils import copy_async_readable_to_buffer, Writable, AsyncReadable
51+
from aleph.sdk.utils import Writable, copy_async_readable_to_buffer
52+
5253
from .conf import settings
5354
from .exceptions import (
5455
BroadcastError,
56+
FileTooLarge,
5557
InvalidMessageError,
5658
MessageNotFoundError,
5759
MultipleMessagesError,
58-
FileTooLarge,
5960
)
6061
from .models import MessagesResponse
6162
from .utils import check_unix_socket_valid, get_message_type_value
@@ -237,12 +238,24 @@ def download_file_ipfs(self, file_hash: str) -> bytes:
237238
self.async_session.download_file_ipfs,
238239
file_hash=file_hash,
239240
)
240-
def download_file_to_buffer(self, file_hash: str, output_buffer: Writable[bytes]) -> bytes:
241-
return self._wrap(self.async_session.download_file_to_buffer, file_hash=file_hash, output_buffer=output_buffer)
242241

243-
def download_file_ipfs_to_buffer(self, file_hash: str, output_buffer: Writable[bytes]) -> bytes:
244-
return self._wrap(self.async_session.download_file_ipfs_to_buffer, file_hash=file_hash, output_buffer=output_buffer)
242+
def download_file_to_buffer(
243+
self, file_hash: str, output_buffer: Writable[bytes]
244+
) -> bytes:
245+
return self._wrap(
246+
self.async_session.download_file_to_buffer,
247+
file_hash=file_hash,
248+
output_buffer=output_buffer,
249+
)
245250

251+
def download_file_ipfs_to_buffer(
252+
self, file_hash: str, output_buffer: Writable[bytes]
253+
) -> bytes:
254+
return self._wrap(
255+
self.async_session.download_file_ipfs_to_buffer,
256+
file_hash=file_hash,
257+
output_buffer=output_buffer,
258+
)
246259

247260
def watch_messages(
248261
self,

src/aleph/sdk/utils.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from enum import Enum
55
from pathlib import Path
66
from shutil import make_archive
7-
from typing import Tuple, Type, Union
7+
from typing import Protocol, Tuple, Type, TypeVar, Union
88
from zipfile import BadZipFile, ZipFile
99

1010
from aleph_message.models import MessageType
@@ -13,13 +13,6 @@
1313
from aleph.sdk.conf import settings
1414
from aleph.sdk.types import GenericMessage
1515

16-
from typing import (
17-
Tuple,
18-
Type,
19-
TypeVar,
20-
Protocol,
21-
)
22-
2316
logger = logging.getLogger(__name__)
2417

2518
try:
@@ -54,7 +47,7 @@ def create_archive(path: Path) -> Tuple[Path, Encoding]:
5447
return archive_path, Encoding.zip
5548
elif os.path.isfile(path):
5649
if path.suffix == ".squashfs" or (
57-
magic and magic.from_file(path).startswith("Squashfs filesystem")
50+
magic and magic.from_file(path).startswith("Squashfs filesystem")
5851
):
5952
return path, Encoding.squashfs
6053
else:
@@ -101,7 +94,7 @@ def write(self, buffer: U) -> int:
10194

10295

10396
async def copy_async_readable_to_buffer(
104-
readable: AsyncReadable[T], buffer: Writable[T], chunk_size: int
97+
readable: AsyncReadable[T], buffer: Writable[T], chunk_size: int
10598
):
10699
while True:
107100
chunk = await readable.read(chunk_size)

tests/unit/test_chain_ethereum.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ async def test_ETHAccount(ethereum_account):
3636

3737
address = account.get_address()
3838
assert address
39-
assert type(address) == str
39+
assert isinstance(address, str)
4040
assert len(address) == 42
4141

4242
pubkey = account.get_public_key()
43-
assert type(pubkey) == str
43+
assert isinstance(pubkey, str)
4444
assert len(pubkey) == 68
4545

4646

@@ -111,9 +111,9 @@ async def test_decrypt_secp256k1(ethereum_account):
111111
content = b"SomeContent"
112112

113113
encrypted = await account.encrypt(content)
114-
assert type(encrypted) == bytes
114+
assert isinstance(encrypted, bytes)
115115
decrypted = await account.decrypt(encrypted)
116-
assert type(decrypted) == bytes
116+
assert isinstance(decrypted, bytes)
117117
assert content == decrypted
118118

119119

tests/unit/test_chain_nuls1.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ async def test_sign_data():
1818
)
1919

2020
assert sign
21-
assert type(sign.pub_key) == bytes
22-
assert type(sign.digest_bytes) == bytes
23-
assert type(sign.sig_ser) == bytes
21+
assert isinstance(sign.pub_key, bytes)
22+
assert isinstance(sign.digest_bytes, bytes)
23+
assert isinstance(sign.sig_ser, bytes)
2424
assert sign.ecc_type is None
2525

2626

@@ -37,9 +37,9 @@ async def test_sign_message():
3737
assert len(sign.sig_ser) == 70
3838

3939
assert sign
40-
assert type(sign.pub_key) == bytes
40+
assert isinstance(sign.pub_key, bytes)
4141
assert sign.digest_bytes is None
42-
assert type(sign.sig_ser) == bytes
42+
assert isinstance(sign.sig_ser, bytes)
4343
assert sign.ecc_type is None
4444

4545

tests/unit/test_chain_solana.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_get_fallback_account():
2727
assert account.CHAIN == "SOL"
2828
assert account.CURVE == "curve25519"
2929
assert account._signing_key.verify_key
30-
assert type(account.private_key) == bytes
30+
assert isinstance(account.private_key, bytes)
3131
assert len(account.private_key) == 32
3232

3333

@@ -42,12 +42,12 @@ async def test_SOLAccount(solana_account):
4242

4343
address = message["sender"]
4444
assert address
45-
assert type(address) == str
45+
assert isinstance(address, str)
4646
# assert len(address) == 44 # can also be 43?
4747
signature = json.loads(message["signature"])
4848

4949
pubkey = base58.b58decode(signature["publicKey"])
50-
assert type(pubkey) == bytes
50+
assert isinstance(pubkey, bytes)
5151
assert len(pubkey) == 32
5252

5353
verify_key = VerifyKey(pubkey)
@@ -61,7 +61,7 @@ async def test_SOLAccount(solana_account):
6161
assert message["sender"] == signature["publicKey"]
6262

6363
pubkey = solana_account.get_public_key()
64-
assert type(pubkey) == str
64+
assert isinstance(pubkey, str)
6565
assert len(pubkey) == 64
6666

6767

@@ -71,9 +71,9 @@ async def test_decrypt_curve25516(solana_account):
7171
content = b"SomeContent"
7272

7373
encrypted = await solana_account.encrypt(content)
74-
assert type(encrypted) == bytes
74+
assert isinstance(encrypted, bytes)
7575
decrypted = await solana_account.decrypt(encrypted)
76-
assert type(decrypted) == bytes
76+
assert isinstance(decrypted, bytes)
7777
assert content == decrypted
7878

7979

@@ -90,7 +90,7 @@ async def test_verify_signature(solana_account):
9090
await solana_account.sign_message(message)
9191
assert message["signature"]
9292
raw_signature = json.loads(message["signature"])["signature"]
93-
assert type(raw_signature) == str
93+
assert isinstance(raw_signature, str)
9494

9595
verify_signature(raw_signature, message["sender"], get_verification_buffer(message))
9696

tests/unit/test_download.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
23
from aleph.sdk import AlephClient
34
from aleph.sdk.conf import settings as sdk_settings
45

@@ -28,6 +29,6 @@ async def test_download(file_hash: str, expected_size: int):
2829
@pytest.mark.asyncio
2930
async def test_download_ipfs(file_hash: str, expected_size: int):
3031
async with AlephClient(api_server=sdk_settings.API_HOST) as client:
31-
file_content = await client.download_file_ipfs(file_hash) ## 5817703 B FILE
32+
file_content = await client.download_file_ipfs(file_hash) # 5817703 B FILE
3233
file_size = len(file_content)
3334
assert file_size == expected_size

0 commit comments

Comments
 (0)