`types-unidiff` is a PEP 561 type stub package providing external type annotations for the `unidiff` library. `unidiff` itself is a Python library for parsing and interacting with unified diff data, allowing programmatic access to file changes, hunks, and lines within a diff. `types-unidiff` is released frequently (up to daily) by the Typeshed project and is designed to be used by static type checkers like MyPy, Pyright, and PyCharm to ensure type correctness in code that uses `unidiff`.
pip install types-unidiff unidiffVerified import paths — ran on the pinned version, not inferred.
This example demonstrates parsing a unified diff string using the `unidiff.PatchSet` class. After `types-unidiff` is installed, a static type checker would be able to provide type hints and check for correctness when interacting with `PatchSet`, `PatchedFile`, and `Hunk` objects.
Pin `types-unidiff` to a specific version or a narrow version range (e.g., `types-unidiff~=0.7.0.20260408`) if strict type checking is critical and unexpected type-checking errors are undesirable. Regularly review changes in new stub versions against your codebase.
Always install both `types-unidiff` and `unidiff` using `pip install types-unidiff unidiff`.
Ensure all imports refer to the runtime package, e.g., `from unidiff import PatchSet`.