Skip to content

Latest commit

 

History

History
36 lines (25 loc) · 854 Bytes

File metadata and controls

36 lines (25 loc) · 854 Bytes

Python Coding Standards

General Guidelines

  • Use 4 spaces per indentation level.
  • Use meaningful variable and function names.
  • Write docstrings for all public modules, classes, functions, and methods.
  • Avoid global variables.
  • Prefer list comprehensions and generator expressions where appropriate.
  • Use type hints for function signatures.

Imports

  • Group imports in the following order: standard library, third-party, local application/library.

Error Handling

  • Use exceptions for error handling, not return codes.
  • Catch specific exceptions, not broad ones.

Testing

  • Write unit tests for all modules.
  • Use pytest or unittest frameworks.

Example

import os
from typing import List

def process_items(items: List[str]) -> None:
    """Process a list of items."""
    for item in items:
        print(item)