Format python

From theafh/ai-modules · View interactive version

Format python is an AI agent skill from the GitHub repository theafh/ai-modules. Apply formatting standards, code quality rules, structure conventions, linting prevention, and best practices when generating or editing Python code (.py). Covers indentation, quoting, imports, naming, line length, type hints, error handling, logging, data structures, testing, and security practices

How to use this skill

Skill file

format_python

Formatting Standards

Code Quality Standards

Code Structure

Linting Prevention (Critical for LLM Code Generation)

Best Practices

Error Handling & Resilience

Performance & Efficiency

Data Structures & Patterns

Type Safety & Documentation

Testing & Maintainability

Security & Safety

Example

"""Module docstring."""

import logging
from typing import Any

# Constants
DEFAULT_TIMEOUT = 30
logger = logging.getLogger(__name__)


class ExampleClass:
    """Example class demonstrating proper patterns."""

    def __init__(self, name: str, value: int | None = None) -> None:
        """Initialize with name and optional value."""
        self.name = name
        self.value = value

    def process_data(self, data: list[dict[str, Any]]) -> bool:
        """Process data and return success status."""
        if not data:
            return False

        for item in data:
            if not isinstance(item, dict):
                return False

        return True

    def get_info(self) -> dict[str, Any]:
        """Get class information."""
        return {
            "name": self.name,
            "value": self.value,
            "has_value": self.value is not None,
        }


def main() -> None:
    """Execute main function."""
    example = ExampleClass("test")
    result = example.process_data([{"id": 1, "name": "item"}])
    logger.info("Result: %s", result)


if __name__ == "__main__":
    main()
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.