Skip to content

Add Type Hints for Better Type Safety and IDE Support #271

@MSM2002

Description

@MSM2002

Add Type Hints for Better Type Safety and IDE Support

Description

Currently, the python-pdfkit library does not provide type hints for its public API. This makes it harder for developers to leverage static type checking tools like mypy and reduces IDE autocompletion and linting capabilities.

Adding type hints will:

  • Improve developer experience by enabling better autocompletion and inline documentation.
  • Allow integration with static analysis tools for catching type-related bugs early.
  • Align the library with modern Python best practices (PEP 484).

Proposed Solution

  • Introduce type hints for all public functions, classes, and method signatures.
  • Add a py.typed marker file to indicate that the package is typed.
  • Ensure compatibility with Python 3.7+ (or the minimum supported version).
  • Optionally, provide a typing_extensions fallback for older versions if needed.

Example:

from typing import Optional, Dict, Any

def from_url(url: str, output_path: Optional[str] = None, options: Optional[Dict[str, Any]] = None) -> bytes:

##Benefits

  • Better IDE support (autocomplete, inline type info).
  • Safer code through static type checking.
  • Easier onboarding for new contributors and users.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions