python-pdfkit icon indicating copy to clipboard operation
python-pdfkit copied to clipboard

Add Type Hints for Better Type Safety and IDE Support

Open MSM2002 opened this issue 2 months ago • 0 comments

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

  • https://peps.python.org/pep-0484/
  • https://peps.python.org/pep-0561/

MSM2002 avatar Nov 17 '25 11:11 MSM2002