Skip to content

Commit 5ab6a9a

Browse files
authored
fix(src): linter errors (flare-foundation#102)
2 parents 5ac3d9b + cdaef1d commit 5ab6a9a

File tree

16 files changed

+81
-67
lines changed

16 files changed

+81
-67
lines changed

examples/02_ingest_pdf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"""
77

88
import asyncio
9-
from pathlib import Path
109
from unittest.mock import AsyncMock, mock_open, patch
1110

1211
from data.create_sample_invoice import create_invoice_and_get_coords
@@ -62,7 +61,7 @@ async def main() -> None:
6261
"use_ocr": False,
6362
"contract_settings": {
6463
"contract_address": "0x0000000000000000000000000000000000000000",
65-
"abi_path": Path(__file__),
64+
"abi_name": "OnchainDataRegistry",
6665
"function_name": "registerDocument",
6766
},
6867
}

examples/03_turnkey_wallet_integration.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,12 @@ async def create_demo_wallet(wallet: TurnkeyWallet) -> tuple[str, str]:
9191
address_info = await wallet.get_address(wallet_id)
9292
print(f"📍 Wallet address: {address_info.address}")
9393
print(f"📍 Derivation path: {address_info.derivation_path}")
94-
95-
return wallet_id, address_info.address
96-
9794
except Exception as e:
9895
print(f"❌ Failed to create wallet: {e}")
9996
# For demo purposes, return mock values
10097
return "demo_wallet_id", "0x742d35Cc6634C0532925a3b8D8C8EE7c9e92bb1b"
98+
else:
99+
return wallet_id, address_info.address
101100

102101

103102
async def register_ai_agent(
@@ -148,12 +147,12 @@ async def simulate_tee_operation(_tee_manager: TEESecurityManager) -> str:
148147
# In production, this would create a secure operation
149148

150149
print("✅ TEE operation simulated (would validate in production)")
151-
return mock_attestation_token
152-
153150
except Exception as e:
154151
print(f"❌ TEE operation failed: {e}")
155152
print(" Using mock attestation for demo purposes")
156153
return mock_attestation_token
154+
else:
155+
return mock_attestation_token
157156

158157

159158
async def execute_ai_transaction(
@@ -202,12 +201,11 @@ async def execute_ai_transaction(
202201
print(f" 📋 Signed transaction: {result['signed_transaction'][:50]}...")
203202
else:
204203
print(f"❌ Transaction failed: {result['error']}")
205-
206-
return result
207-
208204
except Exception as e:
209205
print(f"❌ Transaction execution error: {e}")
210206
return {"success": False, "error": str(e)}
207+
else:
208+
return result
211209

212210

213211
async def demonstrate_policy_enforcement(

examples/data/sample_invoice.pdf

0 Bytes
Binary file not shown.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ select = ["ALL"]
102102
ignore = ["D203", "D212", "COM812", "S105", "D401", "D104", "ANN401", "ISC003", "D107", "FBT001", "FBT002", "FBT003"]
103103

104104
[tool.ruff.lint.extend-per-file-ignores]
105-
"tests/**/*.py" = ["S101", "ARG", "PLR2004", "SLF001", "BLE001", "E501", "T201", "D", "ANN001", "ANN201", "F821"]
105+
"ecosystem_tools_wrapper.py" = ["PLC0415"]
106+
"tests/**/*.py" = ["S", "ARG", "PLR2004", "SLF001", "BLE001", "E501", "T201", "D", "ANN", "F821", "PLC"]
106107
"examples/**/*.py" = ["T201", "BLE001", "D415", "D100", "INP001"]
107108

108109
[tool.pyright]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# flare_ai_kit/adk/__init__.py
22

3-
from ..tool import tool # pyright: ignore[reportUnknownvariableType]
3+
from flare_ai_kit.agent.tool import tool # pyright: ignore[reportUnknownvariableType]
44

55
# This exposes `adk.tool` to users who import `adk`
66
__all__ = ["tool"]

src/flare_ai_kit/agent/adk_agent.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# agent/adk_agent.py
1+
"""Based ADK Agent using all tools."""
2+
23
from google.adk.agents import Agent
34

45
from flare_ai_kit.agent.settings import AgentSettings

src/flare_ai_kit/agent/ecosystem_tools_wrapper.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Wrapper for Google ADK ecosystem tools."""
2+
13
from eth_typing import ChecksumAddress
24
from httpx import HTTPStatusError, RequestError, TimeoutException
35
from web3.contract.async_contract import AsyncContractFunction
@@ -11,9 +13,7 @@
1113

1214
@adk.tool
1315
async def check_balance(address: str) -> float:
14-
"""
15-
Check the balance of a given Flare address in FLR.
16-
"""
16+
"""Check FLR balance of a given address."""
1717
from flare_ai_kit.ecosystem.flare import Flare
1818
from flare_ai_kit.ecosystem.settings import EcosystemSettings
1919

@@ -130,7 +130,8 @@ async def get_ftso_latest_price(feed_name: str) -> float:
130130
settings = EcosystemSettings()
131131
ftso = await FtsoV2.create(settings)
132132
if not ftso:
133-
raise ValueError("FtsoV2 instance not fully initialized. Use FtsoV2.create().")
133+
msg = "FtsoV2 instance not fully initialized. Use FtsoV2.create()."
134+
raise ValueError(msg)
134135

135136
return await ftso.get_latest_price(feed_name)
136137

@@ -159,7 +160,8 @@ async def get_ftso_latest_prices(feed_names: list[str]) -> list[float]:
159160
settings = EcosystemSettings()
160161
ftso = await FtsoV2.create(settings)
161162
if not ftso:
162-
raise ValueError("FtsoV2 instance not fully initialized. Use FtsoV2.create().")
163+
msg = "FtsoV2 instance not fully initialized. Use FtsoV2.create()."
164+
raise ValueError(msg)
163165

164166
return await ftso.get_latest_prices(feed_names)
165167

@@ -193,9 +195,11 @@ async def get_contract_abi(contract_address: str) -> list[dict[str, str]]:
193195
async with explorer:
194196
return await explorer.get_contract_abi(contract_address)
195197
except (HTTPStatusError, RequestError, TimeoutException) as e:
196-
raise ExplorerError(f"Failed to fetch contract ABI: {e}")
198+
msg = f"Failed to fetch contract ABI: {e}"
199+
raise ExplorerError(msg) from e
197200
except AbiError as e:
198-
raise ValueError(f"Invalid ABI response for contract {contract_address}: {e}")
201+
msg = f"Invalid ABI response for contract {contract_address}: {e}"
202+
raise ValueError(msg) from e
199203

200204

201205
# --- Social: X (Twitter) ---
@@ -210,9 +214,8 @@ async def post_to_x(content: str) -> bool:
210214
settings = SocialSettings() # type: ignore[call-arg]
211215
x_client = XClient(settings)
212216
if not x_client.is_configured:
213-
raise ValueError(
214-
"XClient is not configured. Ensure API keys are set in the environment."
215-
)
217+
msg = "XClient is not configured. Ensure API keys are set."
218+
raise ValueError(msg)
216219

217220
return await x_client.post_tweet(content)
218221

@@ -230,7 +233,7 @@ async def send_telegram_message(chat_id: str, message: str) -> bool:
230233
Args:
231234
chat_id: The unique identifier for the target chat
232235
(e.g., '@channelname' or a user ID).
233-
text: The text of the message to send.
236+
message: The text of the message to send.
234237
235238
Returns:
236239
True if the message was sent successfully, False otherwise.
@@ -242,8 +245,7 @@ async def send_telegram_message(chat_id: str, message: str) -> bool:
242245
settings = SocialSettings() # type: ignore[call-arg]
243246
telegram_client = TelegramClient(settings)
244247
if not telegram_client.is_configured:
245-
raise ValueError(
246-
"TelegramClient is not configured. Ensure API token is set in the environment."
247-
)
248+
msg = "TelegramClient is not configured. Ensure API keys are set."
249+
raise ValueError(msg)
248250

249251
return await telegram_client.send_message(chat_id, message)

src/flare_ai_kit/agent/tool.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
1+
"""Generic for ADK tool."""
2+
13
import inspect
24
from collections.abc import Callable
35
from functools import wraps
46
from typing import Any, TypeVar, cast
57

8+
import structlog
69
from google.adk.tools import FunctionTool, LongRunningFunctionTool
710

11+
logger = structlog.get_logger(__name__)
12+
13+
814
RT = TypeVar("RT") # Return type
9-
# ToolUnion = FunctionTool
1015
TOOL_REGISTRY: list[Any] = []
1116

1217

13-
def tool(func: Callable[..., RT]) -> Callable[..., RT]:
18+
def tool(func: Callable[..., RT]) -> Callable[..., RT]: # noqa: UP047
1419
"""
1520
Decorator to register a function as a Gemini-compatible ADK tool.
21+
1622
Automatically wraps async functions using LongRunningFunctionTool,
1723
and sync functions using FunctionTool.
1824
"""
1925
is_async = inspect.iscoroutinefunction(func)
2026

2127
@wraps(func)
2228
def wrapper(*args: Any, **kwargs: Any) -> Any:
23-
print(f"[ADK TOOL] Calling {func.__name__} with args={args}, kwargs={kwargs}")
29+
logger.info("adk_tool", func=func.__name__, args=args, kwargs=kwargs)
2430
return func(*args, **kwargs)
2531

2632
# Choose appropriate wrapper

src/flare_ai_kit/agents/turnkey.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ async def unregister_agent(self, agent_id: str) -> bool:
139139
logger.info("AI agent unregistered successfully", agent_id=agent_id)
140140
return True
141141

142-
async def execute_agent_transaction(
142+
async def execute_agent_transaction( # noqa: PLR0911
143143
self,
144144
agent_transaction: AgentTransaction,
145145
attestation_token: str | None = None,

src/flare_ai_kit/ingestion/settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Settings for Vector RAG."""
22

3-
from pydantic import Field, FilePath, PositiveInt, model_validator
3+
from pydantic import Field, PositiveInt, model_validator
44
from pydantic_settings import BaseSettings, SettingsConfigDict
55

66
DEFAULT_ALLOWED_EXTENSIONS = {
@@ -89,8 +89,8 @@ class OnchainContractSettings(BaseSettings):
8989
contract_address: str = Field(
9090
description="The address of the OnchainDataRegistry smart contract."
9191
)
92-
abi_path: FilePath = Field(
93-
description="The path to the ABI file for the smart contract."
92+
abi_name: str = Field(
93+
description="ABI file name for the smart contract (under flare-ai-kit/abi/)."
9494
)
9595
function_name: str = Field(
9696
"registerDocument",

0 commit comments

Comments
 (0)