Private
Public Access
feat(directives): harvest 7 directives from python.md §17.1-17.7 (banned patterns + boundary exception)
This commit is contained in:
@@ -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: ...
|
||||
```
|
||||
Reference in New Issue
Block a user