Registry / type-stubs / types-unidiff

types-unidiff

JSON →
library0.7.0.20260727pypypi✓ verified 22d ago

`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 unidiff
INSTALL
IMPORT
SIG · TYPES-UNIDIFF
T
types-unidiff
type-stubspythonv0.7.0.20260727
Install
1.6s avg
Import
17ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.7.0.20260727 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.018s · 18MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.016s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PatchSet
from unidiff import PatchSet
from types_unidiff import PatchSet
Type stubs are not meant for direct runtime imports; they are consumed by type checkers. The actual `PatchSet` class is imported from the `unidiff` package.
PatchedFile
from unidiff import PatchedFile
Import `PatchedFile` directly from the `unidiff` package.
Hunk
from unidiff import Hunk
Import `Hunk` directly from the `unidiff` package.

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.

import urllib.request from unidiff import PatchSet # Example unified diff content diff_content = """ diff --git a/file1.py b/file1.py index abcde12..fghij34 100644 --- a/file1.py +++ b/file1.py @@ -1,3 +1,4 @@ -line 1 +new line 1 line 2 line 3 +added line 4 """ # Parse the diff string patch_set = PatchSet(diff_content) # Iterate through patched files for patched_file in patch_set: print(f"File: {patched_file.path}") print(f"Added lines: {patched_file.added}, Removed lines: {patched_file.removed}") for hunk in patched_file: print(f" Hunk header: {hunk.header}") for line in hunk: print(f" {line.line_type} {line.value.strip()}")
Debug
Known issues
breakingStub package versions align with the runtime library (e.g., `types-unidiff==0.7.*` targets `unidiff==0.7.*`). However, any version bump in the stub package can introduce changes that might cause your code to fail type checks, even if the runtime library itself hasn't changed.
fix
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.
affects: All versions
gotcha`types-unidiff` is solely for type checking. It provides no runtime functionality. The actual `unidiff` library must be installed alongside `types-unidiff` for your code to execute correctly.
fix
Always install both `types-unidiff` and `unidiff` using `pip install types-unidiff unidiff`.
affects: All versions
gotchaDo not attempt to import symbols directly from `types_unidiff` (e.g., `from types_unidiff import PatchSet`). Type stubs are consumed by type checkers but are not designed for direct runtime imports. Always import classes and functions from the original `unidiff` package.
fix
Ensure all imports refer to the runtime package, e.g., `from unidiff import PatchSet`.
affects: All versions
Upgrade
Version history
0.7.0.20260727latest on PyPI · released Jul 27, 2026
Audit
Dependencies
unidiffrequiredProvides the runtime functionality for which these type stubs are generated.
Agent activity
38 hits · last 30 days
node
34
OpenAI (training)
1
Resources
types-unidiff — pip install types-unidiff · libregistry