feat(directives): harvest 7 directives from python.md §17.1-17.7 (banned patterns + boundary exception)

This commit is contained in:
ed
2026-07-02 21:49:13 -04:00
parent 41c8678b28
commit f4dfb84681
7 changed files with 172 additions and 0 deletions
@@ -0,0 +1,36 @@
# ban_hasattr_dispatch — v1
**Why this iteration:** Lifted verbatim from `conductor/code_styleguides/python.md` §17.4 (lines 300-326).
This is the baseline encoding — the imperative-ban style currently in production.
Future variants will test alternative encodings (rationale-first, before/after, tabular) against this baseline.
**Source:** `conductor/code_styleguides/python.md:300-326`
---
### 17.4 Banned: `hasattr()` for entity type dispatch
```python
# BANNED:
def handle_event(self, event: Metadata) -> None:
if hasattr(event, 'tool_calls'):
# tool call path
elif hasattr(event, 'source_tier'):
# mma path
elif hasattr(event, 'path'):
# file path
# CORRECT (typed Union dispatch):
def handle_event(self, event: CommsLogEntry | FileItem | HistoryMessage) -> None:
if isinstance(event, CommsLogEntry):
# mma path
elif isinstance(event, FileItem):
# file path
elif isinstance(event, HistoryMessage):
# tool call path
# CORRECT (preferred — refactor so no dispatch is needed):
def _handle_comms_entry(self, event: CommsLogEntry) -> None: ...
def _handle_file_item(self, event: FileItem) -> None: ...
def _handle_history(self, event: HistoryMessage) -> None: ...
```