Skip to content

Commit

Permalink
Update pylint mypy (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeny-stakewise authored Jan 6, 2025
1 parent 5dd7c53 commit 4170736
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 192 deletions.
356 changes: 178 additions & 178 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ python-json-logger = "==2.0.7"
aiohttp = "==3.10.11"

[tool.poetry.group.dev.dependencies]
pylint = "==3.0.1"
mypy = "==1.6.1"
pylint = "==3.3.3"
mypy = "==1.14.1"
isort = "==5.12.0"
pytest = "==7.4.2"
pytest-asyncio = "==0.21.1"
Expand Down Expand Up @@ -64,7 +64,8 @@ disable = [
"C0115", # missing-class-docstring
"C0116", # missing-function-docstring
"R0801", # duplicate-code
"R0903" # too-few-public-methods
"R0903", # too-few-public-methods
"R0917" # Too many positional arguments
]
ignore-paths=["src/.*/tests/.*", "src/test_fixtures/.*"]
ignore=["conftest.py"]
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def warning_verbose(msg: str, *args) -> None: # type: ignore
logger.warning(msg, *args)


def format_error(e: Exception) -> str:
def format_error(e: BaseException) -> str:
if isinstance(e, tenacity.RetryError):
# get original error
e = e.last_attempt.exception() # type: ignore
Expand Down
9 changes: 5 additions & 4 deletions src/exits/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ async def _fetch_last_update_block_replicas(replicas: list[str]) -> BlockNumber
results = await asyncio.gather(
*[_fetch_exit_signature_block(endpoint) for endpoint in replicas], return_exceptions=True
)
blocks = []
blocks: list[BlockNumber] = []
for res in results:
if not isinstance(res, Exception) and res is not None:
if not isinstance(res, BaseException) and res is not None:
blocks.append(res)
if blocks:
return min(blocks)
Expand Down Expand Up @@ -153,14 +153,15 @@ async def _update_exit_signatures(
logger.info('Starting exit signature rotation for %d validators', len(outdated_indexes))
# pylint: disable=duplicate-code
validators = await get_validator_public_keys(outdated_indexes)
deadline = None
approvals_min_interval = 1
deadline: int | None = None
oracles_request: SignatureRotationRequest | None = None

while True:
approval_start_time = time.time()

current_timestamp = get_current_timestamp()
if not deadline or deadline <= current_timestamp:
if not oracles_request or deadline is None or deadline <= current_timestamp:
deadline = current_timestamp + protocol_config.signature_validity_period
oracles_request = await _get_oracles_request(
protocol_config=protocol_config,
Expand Down
2 changes: 1 addition & 1 deletion src/exits/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def send_signature_rotation_requests(
return_exceptions=True,
)
for (address, replicas), result in zip(endpoints, results):
if isinstance(result, Exception):
if isinstance(result, BaseException):
warning_verbose(
'All endpoints for oracle %s failed to sign signature rotation request. '
'Last error: %s',
Expand Down
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def cli() -> None:
multiprocessing.freeze_support()
# Use certificate from certifi only if cafile could not find by ssl.
if ssl.get_default_verify_paths().cafile is None and hasattr(sys, '_MEIPASS'):
# pylint: disable-next=protected-access
# pylint: disable-next=protected-access,no-member
os.environ['SSL_CERT_FILE'] = os.path.join(sys._MEIPASS, 'certifi', 'cacert.pem')

cli()
8 changes: 5 additions & 3 deletions src/validators/signing/key_shares.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import secrets
from typing import TypeAlias
from typing import TypeAlias, cast

from eth_typing import BLSPubkey, BLSSignature
from py_ecc.bls import G2ProofOfPossession
Expand All @@ -9,7 +9,7 @@
pubkey_to_G1,
signature_to_G2,
)
from py_ecc.bls.hash_to_curve import hash_to_G2
from py_ecc.bls.hash_to_curve import HASH, hash_to_G2
from py_ecc.optimized_bls12_381.optimized_curve import (
G1 as P1, # don't confuse group name (G1) with primitive element name (P1)
)
Expand All @@ -30,7 +30,9 @@ def bls_signature_and_public_key_to_shares(
The function splits `signature` and `public_key` to shares so that
each signature share can be verified with corresponding public key share.
"""
message_g2 = hash_to_G2(message, G2ProofOfPossession.DST, G2ProofOfPossession.xmd_hash_function)
message_g2 = hash_to_G2(
message, G2ProofOfPossession.DST, cast(HASH, G2ProofOfPossession.xmd_hash_function)
)

coefficients_int = [secrets.randbelow(curve_order) for _ in range(threshold - 1)]
coefficients_G1 = [multiply(P1, coef) for coef in coefficients_int]
Expand Down
2 changes: 1 addition & 1 deletion src/validators/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def send_approval_requests(
failed_endpoints: list[str] = []

for (address, replicas), result in zip(endpoints, results):
if isinstance(result, Exception):
if isinstance(result, BaseException):
warning_verbose(
'All endpoints for oracle %s failed to sign validators approval request. '
'Last error: %s',
Expand Down

0 comments on commit 4170736

Please sign in to comment.