Code patterns for GitHub Copilot integration.
These patterns help Copilot understand your coding style and preferences.
| """Python patterns for Copilot.""" | |
| # Async pattern | |
| async def fetch_data(url: str) -> dict: | |
| """Fetch data with error handling.""" | |
| async with aiohttp.ClientSession() as session: | |
| async with session.get(url) as response: | |
| response.raise_for_status() | |
| return await response.json() | |
| # Error handling | |
| def safe_operation(func): | |
| """Decorator for safe operations.""" | |
| @wraps(func) | |
| def wrapper(*args, **kwargs): | |
| try: | |
| return func(*args, **kwargs) | |
| except Exception as e: | |
| logger.error(f"Operation failed: {e}") | |
| raise | |
| return wrapper | |
| # Data class | |
| @dataclass | |
| class APIResponse: | |
| status: str | |
| data: dict | |
| errors: list = field(default_factory=list) |