Skip to content

Bump ruff from 0.5.7 to 0.11.7 #23

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

Merged
merged 6 commits into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ruff: noqa
# ruff: noqa: ANN001
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
Expand Down
3 changes: 2 additions & 1 deletion examples/payments/payments.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from algokit_utils import AlgorandClient

from algokit_subscriber.subscriber import AlgorandSubscriber
from algokit_subscriber.types.subscription import SubscribedTransaction
from algokit_utils import AlgorandClient

algorand = AlgorandClient.mainnet()

Expand Down
3 changes: 2 additions & 1 deletion examples/usdc/usdc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from algokit_utils import AlgorandClient

from algokit_subscriber.subscriber import AlgorandSubscriber
from algokit_subscriber.types.subscription import SubscribedTransaction
from algokit_utils import AlgorandClient

algorand = AlgorandClient.mainnet()

Expand Down
42 changes: 21 additions & 21 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ py-algorand-sdk = "^2.7.0"
algokit-utils = "^3.0.0"
python-semantic-release = "^9.8.8"
mypy = "^1.10.1"
ruff = "^0.5.0"
ruff = "^0.11.7"
pytest = "^8.3.5"
pre-commit = "^4.2.0"
black = "^24.8.0"
Expand Down Expand Up @@ -87,8 +87,6 @@ lint.select = [
"RUF", # Ruff-specific rules
]
lint.ignore = [
"ANN101", # no type for self
"ANN102", # no type for cls
"RET505", # allow else after return
"SIM108", # allow if-else in place of ternary
"E111", # indentation is not a multiple of four
Expand Down
14 changes: 7 additions & 7 deletions src/algokit_subscriber/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
__all__ = [
"AlgorandSubscriber",
"AlgorandSubscriberConfig",
"TransactionSubscriptionParams",
"TransactionSubscriptionResult",
"NamedTransactionFilter",
"TransactionFilter",
"EventListener",
"Arc28EventGroup",
"SubscribedTransaction",
"get_subscribed_transactions",
"BalanceChange",
"BalanceChangeRole",
"EventListener",
"NamedTransactionFilter",
"SubscribedTransaction",
"TransactionFilter",
"TransactionSubscriptionParams",
"TransactionSubscriptionResult",
"get_subscribed_transactions",
]
4 changes: 2 additions & 2 deletions src/algokit_subscriber/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def block_response_to_block_data(response: bytes) -> BlockData:
return cast(
BlockData,
"BlockData",
msgpack.unpackb(
response, strict_map_key=False, unicode_errors="surrogateescape"
),
Expand Down Expand Up @@ -41,7 +41,7 @@ def get_blocks_bulk(context: dict[str, int], client: AlgodClient) -> list[BlockD
params={"format": "msgpack"},
response_format="msgpack",
)
decoded = block_response_to_block_data(cast(bytes, response))
decoded = block_response_to_block_data(cast("bytes", response))
blocks.append(decoded)

elapsed_time = time.time() - start_time
Expand Down
3 changes: 1 addition & 2 deletions src/algokit_subscriber/indexer_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ def extract_items(response: TransactionSearchResults) -> list[TransactionResult]
nonlocal current_round
if "message" in response:
raise Exception({"status": 404, **response})
if response["current-round"] > current_round:
current_round = response["current-round"]
current_round = max(current_round, response["current-round"])
return response["transactions"]

def build_request(next_token: str | None = None) -> dict[str, Any]:
Expand Down
8 changes: 5 additions & 3 deletions src/algokit_subscriber/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def __init__(
)

def default_error_handler(
self, error: Any, _str: str | None = None # noqa: ANN401
self,
error: Any, # noqa: ANN401
_str: str | None = None,
) -> None:
raise error

Expand All @@ -56,15 +58,15 @@ def poll_once(self) -> TransactionSubscriptionResult:
Execute a single subscription poll.
"""
watermark = self.config["watermark_persistence"]["get"]() or 0
current_round = cast(dict, self.algod.status())["last-round"]
current_round = cast("dict", self.algod.status())["last-round"]

self.event_emitter.emit(
"before:poll", {"watermark": watermark, "current_round": current_round}
)

poll_result = get_subscribed_transactions(
subscription=cast(
TransactionSubscriptionParams,
"TransactionSubscriptionParams",
{"watermark": watermark, "current_round": current_round, **self.config},
),
algod=self.algod,
Expand Down
56 changes: 24 additions & 32 deletions src/algokit_subscriber/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,13 @@ def filter_transaction(t: TransactionResult) -> bool: # noqa: C901, PLR0912
if subscription.get("receiver"):
if isinstance(subscription["receiver"], str):
result = result and bool(
axfer
and axfer.get("receiver") == subscription["receiver"]
or pay
and pay.get("receiver") == subscription["receiver"]
(axfer and axfer.get("receiver") == subscription["receiver"])
or (pay and pay.get("receiver") == subscription["receiver"])
)
else:
result = result and bool(
axfer
and axfer.get("receiver") in subscription["receiver"]
or pay
and pay.get("receiver") in subscription["receiver"]
(axfer and axfer.get("receiver") in subscription["receiver"])
or (pay and pay.get("receiver") in subscription["receiver"])
)

if subscription.get("type"):
Expand All @@ -312,42 +308,40 @@ def filter_transaction(t: TransactionResult) -> bool: # noqa: C901, PLR0912
if isinstance(subscription["app_id"], int):
result = result and bool(
t.get("created-application-index") == int(subscription["app_id"])
or appl
and appl.get("application-id") == int(subscription["app_id"])
or (
appl
and appl.get("application-id") == int(subscription["app_id"])
)
)
else:
result = result and bool(
(
(t.get("created-application-index") or 0)
in map(int, subscription["app_id"])
)
or appl
and appl.get("application-id", 0)
in map(int, subscription["app_id"])
or (
appl
and appl.get("application-id", 0)
in map(int, subscription["app_id"])
)
)

if subscription.get("asset_id"):
if isinstance(subscription["asset_id"], int | float):
asset_id = int(subscription["asset_id"])
result = result and bool(
t.get("created-asset-index") == asset_id
or acfg
and acfg.get("asset-id") == asset_id
or acfg
and acfg.get("asset-id") == asset_id
or axfer
and axfer.get("asset-id") == asset_id
or (acfg and acfg.get("asset-id") == asset_id)
or (acfg and acfg.get("asset-id") == asset_id)
or (axfer and axfer.get("asset-id") == asset_id)
)
else:
asset_ids = set(map(int, subscription["asset_id"]))
result = result and bool(
t.get("created-asset-index") in asset_ids
or axfer
and axfer.get("asset-id") in asset_ids
or acfg
and acfg.get("asset-id") in asset_ids
or afrz
and afrz.get("asset-id") in asset_ids
or (axfer and axfer.get("asset-id") in asset_ids)
or (acfg and acfg.get("asset-id") in asset_ids)
or (afrz and afrz.get("asset-id") in asset_ids)
)

if subscription.get("min_amount"):
Expand Down Expand Up @@ -485,7 +479,7 @@ def check_single_change(actual_change: dict, change_filter: dict) -> bool:

return any(
any(
check_single_change(cast(dict, actual_change), change_filter)
check_single_change(cast("dict", actual_change), change_filter)
for actual_change in transaction_balance_changes
)
for change_filter in filtered_balance_changes
Expand All @@ -511,7 +505,7 @@ def get_subscribed_transactions( # noqa: C901, PLR0912, PLR0915
max_rounds_to_sync = subscription.get("max_rounds_to_sync") or 500
sync_behaviour = subscription["sync_behaviour"]
current_round = subscription.get("current_round") or cast(
dict[str, Any], algod.status()
"dict[str, Any]", algod.status()
).get("last-round", 0)
block_metadata: list[BlockMetadata] | None = None

Expand Down Expand Up @@ -637,8 +631,7 @@ def get_subscribed_transactions( # noqa: C901, PLR0912, PLR0915
)

logger.debug(
f"Retrieved {len(catchup_transactions)} transactions from round {start_round} to round "
f"{algod_sync_from_round_number - 1} via indexer in {(time.time() - start):.3f}s"
f"Retrieved {len(catchup_transactions)} transactions from round {start_round} to round {algod_sync_from_round_number - 1} via indexer in {(time.time() - start):.3f}s"
)
else:
raise NotImplementedError("Not implemented")
Expand Down Expand Up @@ -670,8 +663,7 @@ def get_subscribed_transactions( # noqa: C901, PLR0912, PLR0915
block_metadata = [block_data_to_block_metadata(b) for b in blocks]

logger.debug(
f"Retrieved {len(block_transactions)} transactions from algod via round(s) {algod_sync_from_round_number}-{end_round} "
f"in {(time.time() - start):.3f}s"
f"Retrieved {len(block_transactions)} transactions from algod via round(s) {algod_sync_from_round_number}-{end_round} in {(time.time() - start):.3f}s"
)
else:
logger.debug(
Expand Down Expand Up @@ -955,7 +947,7 @@ def get_indexer_inner_transactions(
parent_offset = offset()
result.append(
cast(
SubscribedTransaction,
"SubscribedTransaction",
{
**t,
"parent_transaction_id": root["id"],
Expand Down
9 changes: 4 additions & 5 deletions src/algokit_subscriber/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ def get_parent_offset() -> int:
)

if (
block_transaction.get("dt") is None
or block_transaction["dt"].get("itx") is None # type: ignore[union-attr]
block_transaction.get("dt") is None or block_transaction["dt"].get("itx") is None # type: ignore[union-attr]
):
continue

Expand Down Expand Up @@ -447,7 +446,7 @@ def get_child_offset() -> int:
return child_offset + 1

if "get_child_offset" in t:
get_child_offset = cast(TransactionInBlockWithChildOffset, t)[
get_child_offset = cast("TransactionInBlockWithChildOffset", t)[
"get_child_offset"
]

Expand Down Expand Up @@ -496,7 +495,7 @@ def get_child_offset() -> int:
"closing-amount": close_amount,
"created-application-index": created_app_id,
"auth-addr": (
encode_address(cast(bytes, block_transaction.get("sgnr")))
encode_address(cast("bytes", block_transaction.get("sgnr")))
if block_transaction.get("sgnr")
else None
),
Expand Down Expand Up @@ -671,7 +670,7 @@ def get_child_offset() -> int:
for ibt in block_transaction["dt"].get("itx", []) # type: ignore[union-attr]
]

return cast(SubscribedTransaction, convert_bytes_to_base64(result))
return cast("SubscribedTransaction", convert_bytes_to_base64(result))

except Exception as e:
logger.error(
Expand Down
Loading
Loading