Skip to content

Commit 34335f1

Browse files
committed
Add reprs to Diff/Conflicts
1 parent 08fef47 commit 34335f1

4 files changed

Lines changed: 35 additions & 6 deletions

File tree

src/types/diff/diff_py.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,28 @@ pub struct DiffPy;
88

99
make_struct!(InsertedPy(DiffPy) as "Inserted" {
1010
value: PyObject
11-
} impl {});
11+
} impl {
12+
fn __repr__(&self) -> String {
13+
format!("Diff(value: {})", self.value)
14+
}
15+
});
1216

1317
make_struct!(DeletedPy(DiffPy) as "Deleted" {
1418
value: PyObject
15-
} impl {});
19+
} impl {
20+
fn __repr__(&self) -> String {
21+
format!("Deleted(value: {})", self.value)
22+
}
23+
});
1624

1725
make_struct!(ChangedPy(DiffPy) as "Changed" {
1826
old: PyObject,
1927
new: PyObject
20-
} impl {});
28+
} impl {
29+
fn __repr__(&self) -> String {
30+
format!("Changed(old: {}, new: {})", self.old, self.new)
31+
}
32+
});
2133

2234
make_struct!(NestedDiffPy(DiffPy) as "NestedDiff" {
2335
children: Py<PyDict>
@@ -26,4 +38,8 @@ make_struct!(NestedDiffPy(DiffPy) as "NestedDiff" {
2638
let slf = slf.borrow();
2739
PyAnyMethods::get_item(slf.children.as_any().bind(slf.py()), key)
2840
}
41+
42+
fn __repr__(&self) -> String {
43+
format!("NestedDiff(children: {})", self.children)
44+
}
2945
});

src/types/diff/merge_py.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@ make_struct!(BasicPy(ConflictPy) as "Basic" {
1010
old: Option<PyObject>,
1111
change1: PyObject,
1212
change2: PyObject,
13-
} impl {});
13+
} impl {
14+
fn __repr__(&self) -> String {
15+
format!(
16+
"Basic(old: {}, change1: {}, change2: {})",
17+
self.old.as_ref().map(|value| value.to_string()).unwrap_or(String::from("None")),
18+
self.change1,
19+
self.change2,
20+
)
21+
}
22+
});
1423

1524
make_struct!(NestedConflictPy(ConflictPy) as "NestedConflict" {
1625
children: Py<PyDict>,
@@ -19,4 +28,8 @@ make_struct!(NestedConflictPy(ConflictPy) as "NestedConflict" {
1928
let slf = slf.borrow();
2029
PyAnyMethods::get_item(slf.children.as_any().bind(slf.py()), key)
2130
}
31+
32+
fn __repr__(&self) -> String {
33+
format!("NestedConflict(children: {})", self.children)
34+
}
2235
});

stubs/bfp_rs/diff/diff_py.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ class NestedDiff(Diff):
2525
children: dict[str, Diff] | dict[int, Diff]
2626

2727
def __getitem__(self, item: Any) -> Diff:
28-
pass
28+
...

stubs/bfp_rs/diff/merge_py.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ class NestedConflict(Conflict):
1919
children: dict[str, Conflict] | dict[int, Conflict]
2020

2121
def __getitem__(self, item: Any) -> Diff:
22-
pass
22+
...

0 commit comments

Comments
 (0)