-
Notifications
You must be signed in to change notification settings - Fork 0
For Contributors Coding Standards
immjunjie edited this page May 30, 2025
·
1 revision
All team members must adhere to the following coding conventions to ensure consistent style, readability, and maintainability.
| Type | Style | Example |
|---|---|---|
| Variables | snake_case | user_data |
| Functions | snake_case | get_user_data() |
| Class Names | PascalCase | UserManager |
| Constants | UPPER_SNAKE_CASE | MAX_RETRY_COUNT |
| Module/Filenames | snake_case | user_service.py |
- Names should be concise and descriptive. Avoid meaningless abbreviations like
temp,data1, etc. - Boolean names should use prefixes like
is_,has_,can_:is_active,has_permission.
- Use 4 spaces per indentation level (no tabs)
- All code blocks (functions, conditionals, loops) must be properly indented
- No space before parentheses in function calls/declarations:
func(x), notfunc (x) - Operators should have spaces:
a + b, nota+b
- Maximum line length of 100 characters
- Break long expressions with proper indentation
-
Use
#for concise, clear comments# Initialize user data user = User()
-
All functions, classes, and modules must have docstrings using triple quotes (
""")def get_user(user_id: int) -> User: """ Retrieve user object by ID. Args: user_id (int): Unique identifier for user Returns: User: Corresponding user object Raises: UserNotFoundError: If no user exists with given ID """ ...
General order within each module/file:
- Imports (standard library -> third-party -> local modules)
- Constant definitions
- Class/function definitions
- Main logic (e.g.,
if __name__ == "__main__":) - Test code (if present)
- Use
try-exceptblocks for potential errors - Catch specific exceptions, avoid bare
exceptclauses - Log errors for debugging
try:
result = fetch_data()
except ConnectionError as e:
logger.error(f"Connection failed: {e}")Commit messages should follow this format:
<type>(<scope>): <brief description>
Examples:
feat(auth): add OAuth2 login supportfix(ui): resolve button alignment issuedocs(readme): update usage instructions
Common types:
-
feat: New feature -
fix: Bug fix -
docs: Documentation changes -
style: Formatting changes (no logic change) -
refactor: Code refactoring -
test: Test additions/modifications -
chore: Maintenance tasks (build tools, etc.)
- All commits must pass static analysis (flake8, pylint)
- Recommended tools:
- Formatting: black, isort
- Linting: flake8, mypy (for type checking)