with one click
python
// Python rules: type hints, pathlib, f-strings, specific exceptions, dataclasses over plain dicts.
// Python rules: type hints, pathlib, f-strings, specific exceptions, dataclasses over plain dicts.
[HINT] Download the complete skill directory including SKILL.md and all related files
| name | python |
| description | Python rules: type hints, pathlib, f-strings, specific exceptions, dataclasses over plain dicts. |
Use this rule when:
.py)Favor explicit, readable code with clear ownership of data flow and error handling.
for loops (for i in range(len(lst))). Use for item in iterable, comprehensions, enumerate(), zip(), or map()/filter().pathlib.Path over os.path.% formatting and str.format().None and assign inside the function.dataclass or TypedDict over plain dicts for structured data.except:. Catch specific exceptions.with statements for all resources implementing __enter__ / __exit__.Strong rule: do not split functions, methods, classes, or code blocks into overly fine-grained pieces. Keep related statements together as one cohesive chunk unless extraction has a current, concrete reason.
Extract a function only when one of the following is true:
Otherwise, keep the logic inline. A single well-named function with many readable lines is better than many tiny helpers connected only by call chains.
None where a typed value is expected without documenting it.Optional[T] or T | None and check before use.PascalCase. Functions and variables: snake_case. Constants: UPPER_SNAKE_CASE.=, ==, !=, >, >=, <, <=, +, -, *, /, %, etc.).= or any operator across adjacent lines.if, elif, else, for, while, and with bodies. Never write single-line colon-body forms such as if x: return.references/EXAMPLE.md → Early Return.(Python uses indentation rather than braces, so Stroustrup clause layout does not apply directly. Keep elif, else, except, and finally aligned with their leading keyword on a fresh line, as required by the language.)