- Python Version: 3.12+
- Line Length: 88 characters (Black's default)
- Indentation: 4 spaces (no tabs)
- String Formatting: Use f-strings for interpolation
- Standard library imports first
- Third-party imports second
- Local module imports last
- Each group alphabetically sorted
- Use
from typing importfor type hints
Example:
import datetime
import logging
import random
from typing import List, Optional, Set, Dict, Any
from nicegui import ui, app
from src.config.constants import HEADER_TEXT
from src.types.ui_types import BoardType- Functions/Variables:
snake_case - Constants:
UPPER_CASE(defined at top of file) - Classes:
PascalCase - Type Aliases:
PascalCase - Private Methods:
_leading_underscore
- Use type hints for all function signatures
- Use
Optional[T]for nullable types - Use
List,Dict,Set,Tuplefrom typing - Define custom types in
src/types/
- Triple-quoted docstrings for modules and functions
- Brief description at module level
- No inline comments unless absolutely necessary
- Descriptive variable/function names over comments
- Use try/except blocks with specific exceptions
- Log errors using the logging module
- Provide meaningful error messages
- Define UI element styling as class constants
- Use context managers for UI containers
- Separate UI logic from business logic
- Handle disconnected clients gracefully
- Keep functions focused and single-purpose
- Extract constants to config module
- Separate concerns into appropriate modules
- Use type definitions for complex data structures
- Test files:
test_*.py - Test classes:
Test* - Test functions:
test_* - Use pytest fixtures for setup
- Mock external dependencies
- Aim for high test coverage
- Black: Automatic code formatting
- isort: Import sorting with Black compatibility
- flake8: Linting (configured for 88 char lines)
- mypy: Static type checking
All formatting is automated via make format or individual Poetry commands.