Skip to content

Commit f30c324

Browse files
tcoratgerclaude
andauthored
refactor(api): inline import-time _routes global into start() (leanEthereum#983)
Build the aiohttp route list inside start() instead of at module import time. This removes an import-time side effect and a module-level global that was only ever read in one place. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent b3007c1 commit f30c324

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

src/lean_spec/node/api/server.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
logger = logging.getLogger(__name__)
2222

2323

24-
_routes = [web.get(path, handler) for path, handler in ROUTES.items()]
25-
_routes += [web.route(method, path, handler) for method, path, handler in ADMIN_ROUTES]
26-
"""aiohttp route definitions generated from ROUTES and ADMIN_ROUTES."""
27-
2824
# The following classes are implementation details.
2925
# Other implementations may structure their code differently.
3026

@@ -103,8 +99,10 @@ async def start(self) -> None:
10399
# Absence is fine; endpoints return 503 when unset.
104100
app["aggregator_controller"] = self.aggregator_controller
105101

106-
# Add all routes
107-
app.add_routes(_routes)
102+
# Add all routes, generated from ROUTES and ADMIN_ROUTES.
103+
routes = [web.get(path, handler) for path, handler in ROUTES.items()]
104+
routes += [web.route(method, path, handler) for method, path, handler in ADMIN_ROUTES]
105+
app.add_routes(routes)
108106

109107
self._runner = web.AppRunner(app)
110108
await self._runner.setup()

0 commit comments

Comments
 (0)