Code Style Guide
Coding standards and conventions for Qarion ETL.
Python Style
PEP 8 Compliance
Follow PEP 8 style guidelines:
- Use 4 spaces for indentation
- Maximum line length: 100 characters
- Use snake_case for functions and variables
- Use PascalCase for classes
Type Hints
Always use type hints for function signatures:
from typing import Dict, List, Optional, Any
def process_data(
data: Dict[str, Any],
keys: List[str],
default: Optional[str] = None
) -> Dict[str, Any]:
"""Process data with given keys."""
pass
Docstrings
Document all public functions and classes:
def my_function(param1: str, param2: int) -> bool:
"""
Brief description of the function.
Args:
param1: Description of param1
param2: Description of param2
Returns:
Description of return value
Raises:
ValueError: When param1 is invalid
"""
pass
Naming Conventions
- Classes: PascalCase (
MyClass) - Functions: snake_case (
my_function) - Constants: UPPER_SNAKE_CASE (
MY_CONSTANT) - Private: Leading underscore (
_private_method)
Code Organization
Imports
Organize imports:
- Standard library
- Third-party packages
- Local application imports
# Standard library
import os
from typing import Dict, List
# Third-party
import yaml
# Local
from .base import BaseClass
from ..utils import helper_function
Module Structure
"""
Module docstring.
"""
# Imports
# Constants
# Classes
# Functions
Error Handling
Use appropriate exception types:
if not value:
raise ValueError("Value cannot be empty")
if not os.path.exists(path):
raise FileNotFoundError(f"Path not found: {path}")
Testing
- Test files:
test_*.py - Test functions:
test_* - Use descriptive test names
def test_process_data_with_valid_input():
"""Test processing valid data."""
pass