Coding Style and Control Flow
Style and Readability
- Do not use emojis in code or comments.
- Keep log output concise and professional.
- Modules/files:
snake_case(for examplebrowser_agent.py). - Classes:
PascalCase; keep acronyms explicit (for exampleCDPClient,LLMProvider). - Functions/variables:
snake_case; avoid ambiguous abbreviations. - Constants:
UPPER_SNAKE_CASE. - Prefer explicit names when short names are unclear.
Typing and Documentation
- Use
from __future__ import annotations. - Use Python type hints for function arguments and return values.
- Use
typingtypes for complex annotations (for exampleList,Dict,Optional,Any). - Keep docs concise and non-redundant.
- Write key API documentation in English.
Simplicity and Control Flow
- Prefer the smallest correct change with clear control flow.
- Prefer guard clauses and early returns over deep nesting.
- Do not add
elseafter branches that alreadyreturn,raise, orcontinue. - Keep branch depth shallow.
- Maximum nesting depth:
2. - Maximum branches in one
if/elif/elseblock:3. - Refactor to helpers or strategy mapping when more branches are needed.
- Keep functions focused.
- Target length:
<= 40lines (excluding docstrings/comments). - Split oversized functions by responsibility.
- Centralize SDK compatibility/fallback complexity in one private helper.
- New branches must be necessity-driven; do not add speculative compatibility branches.
- During PR updates, prefer removing complexity over adding patch branches.
- Fail fast by default.
- Do not wrap the normal path in broad defensive
tryblocks. - Catch exceptions only when there is a clear recovery action.
- Let unrecoverable errors raise.