Documentation

Docstrings

Use Python docstrings to document modules, classes, and methods. Follow PEP 257 conventions for clarity and consistency.

Example:

class UserManager:
    """
    Manages user operations such as registration and authentication.
    """
    def register(self, data: dict) -> 'User':
        """
        Registers a new user.
        :param data: Dictionary of user data
        :return: User instance
        """
        pass

Inline Comments

Use comments to explain complex or non-obvious code. Place comments above the code they describe.

API Documentation

  • Use tools like Sphinx or MkDocs for generating project documentation.
  • Document API endpoints, request/response formats, and authentication requirements.

Best Practices

  • Keep documentation up to date with code changes.
  • Document public interfaces, expected inputs/outputs, and side effects.
  • Use consistent terminology and formatting.
  • Encourage team members to contribute to documentation.