Utility to diff classes
Project description
classdiff
- Python Class Difffer
This is a small library to diff (data) classes. Different from most existing
diff tools that produce data structures that show adds, removes or changes, this
tool is intended to use for printing a dataclass and higlight the diff with
different color coding, similar to the output of Terraform
or Pulumi
.
Usage
Just pass your classes to the diff function to get back a representation of the diff.
Given the following two classes:
one = SomeResource(
name="my-data",
price=2.3,
quantity=4,
dangerous=True,
other=OtherClass(name="OA"),
not_changed=OtherClass(name="Same"),
)
two = SomeResource(
name="my-data",
price=3.3,
quantity=4,
dangerous=False,
other=OtherClass(name="OB"),
not_changed=OtherClass(name="Same"),
)
Passing them to classdiff.diff
in combinations of (one, None)
, (one, two)
and (None, two)
and printing the lines in the returned value, the following
will be printed. Note that each element in the returned list is of type
DiffInfo
which implements __repr__
to print with proper prefix and color.
Development
All code is formatted and analyzed with black
and ruff
. Tests are run with
pytest
.
› poetry run black .
› poetry run ruff check .
› poetry run mypy .
› poetry run pytest tests/
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for classdiff-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 042b6082c0023a07a3668a7fa0f2a8112cacbedf68303715db7dd7f8073b41a8 |
|
MD5 | 3e361b815612f669a0ea23665761b7eb |
|
BLAKE2b-256 | 02c917bda214fdb35fa68c5f6cdfeebc19e4a2381ff45299bea38d1f7da41bdf |