Skip to content

Commit 5c8a6fc

Browse files
tcoratgerclaude
andauthored
refactor: rename exception variable from exc to exception (leanEthereum#803)
Expands the `exc` abbreviation used in `except X as exc:` clauses to the full word `exception`, matching the no-abbreviations rule in CLAUDE.md. Adds the rule explicitly so future code keeps the full spelling. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 42ef512 commit 5c8a6fc

14 files changed

Lines changed: 49 additions & 41 deletions

File tree

CLAUDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ subspecifications that the Lean Ethereum protocol relies on.
4040
- `prop``proposal`, `conn``connection`, `addr``address`, `cert``certificate`
4141
- `privkey``private_key`, `elem``element`, `buf``buffer`, `dir``directory`
4242
- `len``length` (inside a name, never the `len()` builtin), `fe``field_elements`
43+
- `exc` / `e``exception` (in `except X as exc:` clauses, use `exception`; the stdlib
44+
`exc_info` name is still kept verbatim)
4345
- Use the correct domain term, not just any expansion: a validator is referenced by its
4446
INDEX, so `validator_id``validator_index` (never `validator_id`).
4547
- KEEP canonical protocol identifiers that genuinely use "ID": `peer_id`, `node_id`,

packages/testing/src/consensus_testing/test_fixtures/networking_codec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ def _make_decode_failure(self) -> dict[str, Any]:
144144
exception_raised: Exception | None = None
145145
try:
146146
decoder(raw)
147-
except Exception as exc:
148-
exception_raised = exc
147+
except Exception as exception:
148+
exception_raised = exception
149149

150150
if exception_raised is None:
151151
raise AssertionError(

packages/testing/src/consensus_testing/test_fixtures/ssz.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ def _make_decode_failure(self) -> "SSZTest":
121121
exception_raised: Exception | None = None
122122
try:
123123
decoder.decode_bytes(raw)
124-
except Exception as exc:
125-
exception_raised = exc
124+
except Exception as exception:
125+
exception_raised = exception
126126

127127
if exception_raised is None:
128128
raise AssertionError(

packages/testing/src/consensus_testing/test_fixtures/verify_proofs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ def make_fixture(self) -> VerifyProofsTest:
155155
# a comparable "expected X got Y" message instead of crashing the filler.
156156
try:
157157
candidate.verify(public_keys, message, slot)
158-
except Exception as exc:
159-
exception_raised = exc
158+
except Exception as exception:
159+
exception_raised = exception
160160

161161
if self.expect_exception is None:
162162
if exception_raised is not None:

src/lean_spec/cli/bootstrap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ def from_cli_args(cls, args: CliArgs) -> NodeBootstrap:
118118
for s in args.aggregate_subnet_ids_raw.split(",")
119119
if s.strip()
120120
)
121-
except ValueError as exc:
121+
except ValueError as exception:
122122
raise CliValidationError(
123123
"--aggregate-subnet-ids expects comma-separated integers, "
124124
f"got {args.aggregate_subnet_ids_raw!r}"
125-
) from exc
125+
) from exception
126126

127127
# Genesis load.
128128
logger.info("Loading genesis from %s", args.genesis_path)

src/lean_spec/cli/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def main() -> None:
2727
# Validate cross-field rules and load referenced files.
2828
try:
2929
boot = NodeBootstrap.from_cli_args(args)
30-
except (CliValidationError, FileNotFoundError) as exc:
31-
logger.error("%s", exc)
30+
except (CliValidationError, FileNotFoundError) as exception:
31+
logger.error("%s", exception)
3232
sys.exit(1)
3333

3434
# Run the node under an event loop until shutdown or a fatal error.

src/lean_spec/node/api/endpoints/aggregator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ async def handle_toggle(request: web.Request) -> web.Response:
5858

5959
try:
6060
payload = await request.json()
61-
except json.JSONDecodeError as exc:
62-
raise web.HTTPBadRequest(reason="Invalid JSON body") from exc
61+
except json.JSONDecodeError as exception:
62+
raise web.HTTPBadRequest(reason="Invalid JSON body") from exception
6363

6464
if not isinstance(payload, dict) or "enabled" not in payload:
6565
raise web.HTTPBadRequest(reason="Missing 'enabled' field in body")

src/lean_spec/node/networking/client/event_source/live.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,8 @@ async def start_serving(
424424
logger.info("Connecting to bootnode %s", multiaddr)
425425
try:
426426
peer_id = await self.dial(multiaddr)
427-
except Exception as exc:
428-
logger.warning("Failed to connect to bootnode %s: %s", multiaddr, exc)
427+
except Exception as exception:
428+
logger.warning("Failed to connect to bootnode %s: %s", multiaddr, exception)
429429
continue
430430
if peer_id is not None:
431431
logger.info("Connected to bootnode, peer_id=%s", peer_id)

src/lean_spec/node/sync/checkpoint_sync.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ async def fetch_finalized_state(url: str, state_class: type[State]) -> State:
9090

9191
return state
9292

93-
except httpx.RequestError as exc:
93+
except httpx.RequestError as exception:
9494
raise CheckpointSyncError(
95-
f"Network error while connecting to {exc.request.url}: {exc}"
96-
) from exc
97-
except httpx.HTTPStatusError as exc:
95+
f"Network error while connecting to {exception.request.url}: {exception}"
96+
) from exception
97+
except httpx.HTTPStatusError as exception:
9898
raise CheckpointSyncError(
99-
f"HTTP error {exc.response.status_code}: {exc.response.text[:200]}"
100-
) from exc
99+
f"HTTP error {exception.response.status_code}: {exception.response.text[:200]}"
100+
) from exception
101101
except Exception as e:
102102
raise CheckpointSyncError(f"Failed to fetch state: {e}") from e
103103

src/lean_spec/node/sync/head_sync.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,10 @@ async def _process_cached_descendants(
310310
)
311311
processed_count += description_count
312312

313-
except Exception as exc:
313+
except Exception as exception:
314314
# Processing failed. Leave in cache for retry or discard.
315315
# Do not cascade the error; continue with other children.
316-
logger.debug("Failed to process cached descendant: %s", exc)
316+
logger.debug("Failed to process cached descendant: %s", exception)
317317

318318
finally:
319319
self._processing.discard(child_root)

0 commit comments

Comments
 (0)