You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .agents/skills/usethis-python-functions/SKILL.md
+38-1Lines changed: 38 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ description: Guidelines for Python function design, including return types and s
4
4
compatibility: usethis, Python
5
5
license: MIT
6
6
metadata:
7
-
version: "1.2"
7
+
version: "1.3"
8
8
---
9
9
10
10
# Function Design Guidelines
@@ -77,6 +77,43 @@ def use_tool() -> None:
77
77
register_group("dev")
78
78
```
79
79
80
+
## Never return bool to signal success or failure
81
+
82
+
Functions must not return `True` for success and `False` for failure. This is a C-style pattern that is un-Pythonic and error-prone. Use exception raising and handling instead.
83
+
84
+
### Why this matters
85
+
86
+
- Callers can silently ignore a `False` return, leading to bugs that go unnoticed.
87
+
- Exceptions carry context (message, traceback, type) that a bare `bool` cannot.
88
+
- Python's exception system is designed for this purpose — using it makes intent explicit and control flow clear.
89
+
90
+
### What to do instead
91
+
92
+
1.**Raise an exception** when an operation fails. Use a built-in exception type or define a custom one.
93
+
2.**Return `None`** (or nothing) on success if the function has no meaningful value to return.
94
+
3.**Let exceptions propagate** to callers, who can catch them at the appropriate level.
95
+
96
+
### Example
97
+
98
+
```python
99
+
# Bad: caller must remember to check the return value.
Returning `bool` is appropriate when the function answers a yes/no question (a predicate), such as `is_tool_used()` or `has_build_system()`. The guideline above applies only to functions where `bool` encodes an operation's outcome rather than a factual query.
116
+
80
117
## Avoid returning tuples
81
118
82
119
Functions should not return tuples. Tuple returns obscure the meaning of each element, making call sites harder to read and fragile to refactor.
0 commit comments