Skip to content

Commit c1110c6

Browse files
committed
Fix typing warnings
- Use builtin types instead of importing from `typing` - Not all the types were updated
1 parent 4b6494c commit c1110c6

40 files changed

+251
-260
lines changed

safe_transaction_service/account_abstraction/helpers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import dataclasses
2-
from typing import List
32

43
from eth_typing import ChecksumAddress
54
from safe_eth.eth import EthereumClient
@@ -19,7 +18,7 @@ class DecodedInitCode:
1918
salt_nonce: int
2019
expected_address: ChecksumAddress # Expected Safe deployment address
2120
# Safe creation data
22-
owners: List[ChecksumAddress]
21+
owners: list[ChecksumAddress]
2322
threshold: int
2423
to: ChecksumAddress
2524
data: bytes

safe_transaction_service/account_abstraction/serializers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import datetime
2-
from typing import Any, Dict, List, Optional
2+
from typing import Any, Optional
33

44
from django.conf import settings
55
from django.db import transaction
@@ -39,9 +39,9 @@ class SafeOperationSignatureValidatorMixin:
3939
def __init__(self, *args, **kwargs):
4040
super().__init__(*args, **kwargs)
4141
self.ethereum_client = get_auto_ethereum_client()
42-
self._deployment_owners: List[ChecksumAddress] = []
42+
self._deployment_owners: list[ChecksumAddress] = []
4343

44-
def _get_owners(self, safe_address: ChecksumAddress) -> List[ChecksumAddress]:
44+
def _get_owners(self, safe_address: ChecksumAddress) -> list[ChecksumAddress]:
4545
"""
4646
:param safe_address:
4747
:return: `init_code` decoded owners if Safe is not deployed or current blockchain owners if Safe is deployed
@@ -59,7 +59,7 @@ def _validate_signature(
5959
safe_operation_hash: bytes,
6060
safe_operation_hash_preimage: bytes,
6161
signature: bytes,
62-
) -> List[SafeSignature]:
62+
) -> list[SafeSignature]:
6363
safe_owners = self._get_owners(safe_address)
6464
parsed_signatures = SafeSignature.parse_signature(
6565
signature,
@@ -375,7 +375,7 @@ def validate(self, attrs):
375375
@transaction.atomic
376376
def save(self, **kwargs):
377377
safe_signatures = self.validated_data["safe_signatures"]
378-
safe_operation_confirmations: List[SafeOperationConfirmation] = []
378+
safe_operation_confirmations: list[SafeOperationConfirmation] = []
379379
for safe_signature in safe_signatures:
380380
safe_operation_confirmation, created = (
381381
SafeOperationConfirmation.objects.get_or_create(
@@ -438,7 +438,7 @@ class SafeOperationResponseSerializer(serializers.Serializer):
438438
confirmations = serializers.SerializerMethodField()
439439
prepared_signature = serializers.SerializerMethodField()
440440

441-
def get_confirmations(self, obj: SafeOperationModel) -> Dict[str, Any]:
441+
def get_confirmations(self, obj: SafeOperationModel) -> dict[str, Any]:
442442
"""
443443
Filters confirmations queryset
444444

safe_transaction_service/account_abstraction/services/aa_processor_service.py

Lines changed: 66 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
from functools import cache
3-
from typing import List, Optional, Sequence, Tuple
3+
from typing import Optional, Sequence
44

55
from django.conf import settings
66
from django.db import transaction
@@ -73,8 +73,8 @@ def __init__(
7373
self.supported_entry_points = supported_entry_points
7474

7575
def get_user_operation_hashes_from_logs(
76-
self, safe_address: ChecksumAddress, logs: [Sequence[LogReceipt]]
77-
) -> List[HexBytes]:
76+
self, safe_address: ChecksumAddress, logs: Sequence[LogReceipt]
77+
) -> list[HexBytes]:
7878
"""
7979
:param safe_address:
8080
:param logs:
@@ -109,7 +109,7 @@ def index_safe_operation_confirmations(
109109
signature: bytes,
110110
safe_operation_model: SafeOperationModel,
111111
safe_operation: SafeOperation,
112-
) -> List[SafeOperationConfirmationModel]:
112+
) -> list[SafeOperationConfirmationModel]:
113113
"""
114114
Creates missing ``SafeOperationConfirmations``
115115
@@ -144,7 +144,7 @@ def index_safe_operation(
144144
user_operation_model: UserOperationModel,
145145
user_operation: UserOperation,
146146
user_operation_receipt: UserOperationReceipt,
147-
) -> Optional[Tuple[SafeOperationModel, SafeOperation]]:
147+
) -> Optional[tuple[SafeOperationModel, SafeOperation]]:
148148
"""
149149
Creates or updates a Safe Operation
150150
@@ -206,7 +206,7 @@ def index_safe_operation(
206206

207207
def index_user_operation_receipt(
208208
self, user_operation_model: UserOperationModel
209-
) -> Tuple[UserOperationReceiptModel, UserOperationReceipt]:
209+
) -> tuple[UserOperationReceiptModel, UserOperationReceipt]:
210210
"""
211211
Stores UserOperationReceipt. Can never be updated as if ``UserOperationReceipt`` is on database indexing
212212
``UserOperation`` is not required
@@ -277,7 +277,7 @@ def index_user_operation(
277277
safe_address: ChecksumAddress,
278278
user_operation_hash: HexBytes,
279279
ethereum_tx: history_models.EthereumTx,
280-
) -> Tuple[UserOperationModel, UserOperation]:
280+
) -> tuple[UserOperationModel, UserOperation] | None:
281281
"""
282282
Index ``UserOperation``, ``SafeOperation`` and ``UserOperationReceipt`` for the given ``UserOperation`` log
283283
@@ -294,72 +294,73 @@ def index_user_operation(
294294
safe_address,
295295
user_operation_hash_hex,
296296
)
297-
else:
297+
return None
298+
299+
logger.debug(
300+
"[%s] Retrieving UserOperation from Bundler with user-operation-hash=%s on tx-hash=%s",
301+
safe_address,
302+
user_operation_hash_hex,
303+
ethereum_tx.tx_hash,
304+
)
305+
user_operation = self.bundler_client.get_user_operation_by_hash(
306+
user_operation_hash_hex
307+
)
308+
if not user_operation:
309+
self.bundler_client.get_user_operation_by_hash.cache_clear()
310+
raise BundlerClientException(
311+
f"user-operation={user_operation_hash_hex} returned `null`"
312+
)
313+
if isinstance(user_operation, UserOperationV07):
314+
raise UserOperationNotSupportedException(
315+
f"user-operation={user_operation_hash_hex} for EntryPoint v0.7.0 is not supported"
316+
)
317+
318+
try:
319+
user_operation_model = UserOperationModel.objects.get(
320+
hash=user_operation_hash_hex
321+
)
298322
logger.debug(
299-
"[%s] Retrieving UserOperation from Bundler with user-operation-hash=%s on tx-hash=%s",
323+
"[%s] Updating UserOperation with user-operation=%s on tx-hash=%s",
300324
safe_address,
301325
user_operation_hash_hex,
302326
ethereum_tx.tx_hash,
303327
)
304-
user_operation = self.bundler_client.get_user_operation_by_hash(
305-
user_operation_hash_hex
306-
)
307-
if not user_operation:
308-
self.bundler_client.get_user_operation_by_hash.cache_clear()
309-
raise BundlerClientException(
310-
f"user-operation={user_operation_hash_hex} returned `null`"
311-
)
312-
if isinstance(user_operation, UserOperationV07):
313-
raise UserOperationNotSupportedException(
314-
f"user-operation={user_operation_hash_hex} for EntryPoint v0.7.0 is not supported"
315-
)
316-
317-
try:
318-
user_operation_model = UserOperationModel.objects.get(
319-
hash=user_operation_hash_hex
320-
)
321-
logger.debug(
322-
"[%s] Updating UserOperation with user-operation=%s on tx-hash=%s",
323-
safe_address,
324-
user_operation_hash_hex,
325-
ethereum_tx.tx_hash,
326-
)
327-
user_operation_model.signature = user_operation.signature
328-
user_operation_model.ethereum_tx = ethereum_tx
329-
user_operation_model.save(update_fields=["signature", "ethereum_tx"])
330-
except UserOperationModel.DoesNotExist:
331-
logger.debug(
332-
"[%s] Storing UserOperation with user-operation=%s on tx-hash=%s",
333-
safe_address,
334-
user_operation_hash_hex,
335-
ethereum_tx.tx_hash,
336-
)
337-
user_operation_model = UserOperationModel.objects.create(
338-
ethereum_tx=ethereum_tx,
339-
hash=user_operation_hash_hex,
340-
sender=user_operation.sender,
341-
nonce=user_operation.nonce,
342-
init_code=user_operation.init_code,
343-
call_data=user_operation.call_data,
344-
call_gas_limit=user_operation.call_gas_limit,
345-
verification_gas_limit=user_operation.verification_gas_limit,
346-
pre_verification_gas=user_operation.pre_verification_gas,
347-
max_fee_per_gas=user_operation.max_fee_per_gas,
348-
max_priority_fee_per_gas=user_operation.max_priority_fee_per_gas,
349-
paymaster=user_operation.paymaster,
350-
paymaster_data=user_operation.paymaster_data,
351-
signature=user_operation.signature,
352-
entry_point=user_operation.entry_point,
353-
)
354-
355-
_, user_operation_receipt = self.index_user_operation_receipt(
356-
user_operation_model
328+
user_operation_model.signature = user_operation.signature
329+
user_operation_model.ethereum_tx = ethereum_tx
330+
user_operation_model.save(update_fields=["signature", "ethereum_tx"])
331+
except UserOperationModel.DoesNotExist:
332+
logger.debug(
333+
"[%s] Storing UserOperation with user-operation=%s on tx-hash=%s",
334+
safe_address,
335+
user_operation_hash_hex,
336+
ethereum_tx.tx_hash,
357337
)
358-
self.index_safe_operation(
359-
user_operation_model, user_operation, user_operation_receipt
338+
user_operation_model = UserOperationModel.objects.create(
339+
ethereum_tx=ethereum_tx,
340+
hash=user_operation_hash_hex,
341+
sender=user_operation.sender,
342+
nonce=user_operation.nonce,
343+
init_code=user_operation.init_code,
344+
call_data=user_operation.call_data,
345+
call_gas_limit=user_operation.call_gas_limit,
346+
verification_gas_limit=user_operation.verification_gas_limit,
347+
pre_verification_gas=user_operation.pre_verification_gas,
348+
max_fee_per_gas=user_operation.max_fee_per_gas,
349+
max_priority_fee_per_gas=user_operation.max_priority_fee_per_gas,
350+
paymaster=user_operation.paymaster,
351+
paymaster_data=user_operation.paymaster_data,
352+
signature=user_operation.signature,
353+
entry_point=user_operation.entry_point,
360354
)
361355

362-
return user_operation_model, user_operation
356+
_, user_operation_receipt = self.index_user_operation_receipt(
357+
user_operation_model
358+
)
359+
self.index_safe_operation(
360+
user_operation_model, user_operation, user_operation_receipt
361+
)
362+
363+
return user_operation_model, user_operation
363364

364365
def process_aa_transaction(
365366
self, safe_address: ChecksumAddress, ethereum_tx: history_models.EthereumTx

safe_transaction_service/analytics/services/analytics_service.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
from functools import cache
3-
from typing import List
43

54
from safe_transaction_service.utils.redis import get_redis
65

@@ -13,7 +12,7 @@ def get_analytics_service() -> "AnalyticsService":
1312
class AnalyticsService:
1413
REDIS_TRANSACTIONS_PER_SAFE_APP = "analytics_transactions_per_safe_app"
1514

16-
def get_safe_transactions_per_safe_app(self) -> List:
15+
def get_safe_transactions_per_safe_app(self) -> list[dict]:
1716
redis = get_redis()
1817
analytic_result = redis.get(self.REDIS_TRANSACTIONS_PER_SAFE_APP)
1918
if analytic_result:

safe_transaction_service/contracts/management/commands/setup_safe_contracts.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
from typing import List, Tuple
32

43
from django.core.files import File
54
from django.core.management import BaseCommand, CommandError
@@ -108,16 +107,16 @@ def handle(self, *args, **options):
108107

109108
@staticmethod
110109
def _get_deployments_by_chain_and_version(
111-
versions: List[str], chain_id: str
112-
) -> List[Tuple[str, str, str]]:
110+
versions: list[str], chain_id: str
111+
) -> list[tuple[str, str, str]]:
113112
"""
114113
Get the list of contracts for the given versions and chain.
115114
116115
:param versions: list of versions
117116
:param chain_id: chain id
118117
:return: list of (version, contract_name, contract_address)
119118
"""
120-
chain_deployments: List[Tuple[str, str, str]] = []
119+
chain_deployments: list[tuple[str, str, str]] = []
121120
for version in versions:
122121
for contract_name, addresses in safe_deployments[version].items():
123122
for contract_address in addresses.get(chain_id, []):
@@ -127,16 +126,16 @@ def _get_deployments_by_chain_and_version(
127126

128127
@staticmethod
129128
def _get_default_deployments_by_version_on_chain(
130-
versions: List[str], ethereum_client: EthereumClient
131-
) -> List[Tuple[str, str, str]]:
129+
versions: list[str], ethereum_client: EthereumClient
130+
) -> list[tuple[str, str, str]]:
132131
"""
133132
Get the default deployments by version actually deployed on chain.
134133
135134
:param versions: list of versions
136135
:param ethereum_client: Ethereum client
137136
:return: list of (version, contract_name, contract_address)
138137
"""
139-
chain_deployments: List[Tuple[str, str, str]] = []
138+
chain_deployments: list[tuple[str, str, str]] = []
140139
for version in versions:
141140
for contract_name, addresses in default_safe_deployments[version].items():
142141
for contract_address in addresses:
@@ -149,7 +148,7 @@ def _get_default_deployments_by_version_on_chain(
149148

150149
@staticmethod
151150
def _create_or_update_contracts_from_deployments(
152-
deployments: List[Tuple[str, str, str]],
151+
deployments: list[tuple[str, str, str]],
153152
queryset,
154153
force_update_contracts: bool,
155154
logo_file: File,

safe_transaction_service/contracts/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import operator
33
import os
44
from logging import getLogger
5-
from typing import Any, Dict, List, Optional
5+
from typing import Any, Optional
66

77
from django.conf import settings
88
from django.core.exceptions import ValidationError
@@ -38,7 +38,7 @@ def get_file_storage():
3838
return default_storage
3939

4040

41-
def validate_abi(value: Dict[str, Any]):
41+
def validate_abi(value: dict[str, Any]):
4242
try:
4343
if not value:
4444
raise ValueError("Empty ABI not allowed")
@@ -66,7 +66,7 @@ class ContractAbi(models.Model):
6666
def __str__(self):
6767
return f"ContractABI {self.relevance} - {self.description}"
6868

69-
def abi_functions(self) -> List[str]:
69+
def abi_functions(self) -> list[str]:
7070
return [x["name"] for x in self.abi if x["type"] == "function"]
7171

7272
def save(self, *args, **kwargs) -> None:

0 commit comments

Comments
 (0)