Skip to content

Commit 6f0d2ba

Browse files
docs: add Empty Method Bodies coding standard for pass vs ... convention
Co-authored-by: eavanvalkenburg <13749212+eavanvalkenburg@users.noreply.github.com>
1 parent 75114e3 commit 6f0d2ba

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

python/CODING_STANDARD.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,39 @@ user_msg = UserMessage(content="Hello, world!")
145145
asst_msg = AssistantMessage(content="Hello, world!")
146146
```
147147

148+
### Empty Method Bodies
149+
150+
Use `pass` for empty method bodies rather than `...` (Ellipsis). The `...` literal should be reserved for `@overload` stubs and `= ...` default argument sentinels, where it carries idiomatic meaning.
151+
152+
```python
153+
# ✅ Preferred - concrete no-op method body
154+
async def on_checkpoint_restore(self, state: dict[str, Any]) -> None:
155+
"""Hook called when the workflow is restored from a checkpoint."""
156+
pass
157+
158+
# ✅ Preferred - Protocol method stub
159+
class CheckpointStorage(Protocol):
160+
async def save(self, checkpoint: WorkflowCheckpoint) -> CheckpointID:
161+
"""Save a checkpoint and return its ID."""
162+
pass
163+
164+
# ✅ Preferred - abstract method
165+
@abstractmethod
166+
async def plan(self, context: Context) -> Message:
167+
"""Create a plan for the task."""
168+
raise NotImplementedError
169+
170+
# ✅ Acceptable - @overload stubs and default argument sentinels use ...
171+
@overload
172+
def run(self, stream: Literal[True]) -> ResponseStream: ...
173+
@overload
174+
def run(self, stream: Literal[False] = ...) -> Response: ...
175+
176+
# ❌ Avoid - ... in concrete or Protocol method bodies
177+
async def on_checkpoint_restore(self, state: dict[str, Any]) -> None:
178+
...
179+
```
180+
148181
### Import Structure
149182

150183
The package follows a flat import structure:

0 commit comments

Comments
 (0)