Skip to content

Commit 202e8ba

Browse files
author
Irving Popovetsky
committed
phase 8
1 parent e6bf9d4 commit 202e8ba

3 files changed

Lines changed: 42 additions & 9 deletions

File tree

docs/UPGRADE_PLAN.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,10 @@ ENTRYPOINT ["python3", "-m", "pybot"]
12721272

12731273
---
12741274

1275-
## Phase 8: Fix Plugin Files (Day 5-6)
1275+
## Phase 8: Fix Plugin Files (Day 5-6) ✅ COMPLETE
1276+
1277+
> **Status**: Completed January 4, 2026
1278+
> **Result**: Both custom plugins modernized - removed asyncio.coroutine(), added type hints
12761279
12771280
### 8.1 Update pybot/plugins/api/plugin.py
12781281

pybot/plugins/airtable/plugin.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@
22
import logging
33
import os
44
from collections import defaultdict
5+
from typing import Any, Callable, Coroutine
56

67
from pybot.plugins.airtable import endpoints
78
from pybot.plugins.airtable.api import AirtableAPI
89

910
logger = logging.getLogger(__name__)
1011

12+
# Type alias for async handlers
13+
AsyncHandler = Callable[..., Coroutine[Any, Any, Any]]
14+
15+
16+
def _ensure_async(handler: Callable) -> AsyncHandler:
17+
"""Ensure handler is an async function."""
18+
if not asyncio.iscoroutinefunction(handler):
19+
raise TypeError(
20+
f"Handler {handler.__name__} must be an async function (defined with 'async def')"
21+
)
22+
return handler
23+
1124

1225
class AirtablePlugin:
1326
__name__ = "airtable"
@@ -21,7 +34,13 @@ def __init__(self):
2134

2235
self.routers = {"request": RequestRouter()}
2336

24-
def load(self, sirbot, api_key=None, base_key=None, verify=None):
37+
def load(
38+
self,
39+
sirbot: Any,
40+
api_key: str | None = None,
41+
base_key: str | None = None,
42+
verify: str | None = None
43+
) -> None:
2544
self.session = sirbot.http_session
2645
self.api_key = api_key or os.environ.get("AIRTABLE_API_KEY", "")
2746
self.base_key = base_key or os.environ.get("AIRTABLE_BASE_KEY", "")
@@ -31,9 +50,8 @@ def load(self, sirbot, api_key=None, base_key=None, verify=None):
3150

3251
sirbot.router.add_route("POST", "/airtable/request", endpoints.incoming_request)
3352

34-
def on_request(self, request, handler, **kwargs):
35-
if not asyncio.iscoroutinefunction(handler):
36-
handler = asyncio.coroutine(handler)
53+
def on_request(self, request: str, handler: AsyncHandler, **kwargs: Any) -> None:
54+
handler = _ensure_async(handler)
3755
options = {**kwargs, "wait": False}
3856
self.routers["request"].register(request, (handler, options))
3957

pybot/plugins/api/plugin.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
import asyncio
22
import logging
33
from collections import defaultdict
4+
from typing import Any, Callable, Coroutine
45

56
from pybot.plugins.api import endpoints
67

78
logger = logging.getLogger(__name__)
89

10+
# Type alias for async handlers
11+
AsyncHandler = Callable[..., Coroutine[Any, Any, Any]]
12+
13+
14+
def _ensure_async(handler: Callable) -> AsyncHandler:
15+
"""Ensure handler is an async function."""
16+
if not asyncio.iscoroutinefunction(handler):
17+
raise TypeError(
18+
f"Handler {handler.__name__} must be an async function (defined with 'async def')"
19+
)
20+
return handler
21+
922

1023
class APIPlugin:
1124
__name__ = "api"
@@ -14,7 +27,7 @@ def __init__(self):
1427
self.session = None
1528
self.routers = {"slack": SlackAPIRequestRouter()}
1629

17-
def load(self, sirbot):
30+
def load(self, sirbot: Any) -> None:
1831
self.session = sirbot.http_session
1932

2033
sirbot.router.add_route(
@@ -24,9 +37,8 @@ def load(self, sirbot):
2437
"POST", "/pybot/api/v1/slack/{resource}", endpoints.slack_api
2538
)
2639

27-
def on_get(self, request, handler, **kwargs):
28-
if not asyncio.iscoroutinefunction(handler):
29-
handler = asyncio.coroutine(handler)
40+
def on_get(self, request: str, handler: AsyncHandler, **kwargs: Any) -> None:
41+
handler = _ensure_async(handler)
3042
options = {**kwargs, "wait": False}
3143
self.routers["slack"].register(request, (handler, options))
3244

0 commit comments

Comments
 (0)