Skip to content

Commit e8a1c25

Browse files
authored
fix: Channel.__rich_repr__ checks ndarray default value (#212)
1 parent 5ad083d commit e8a1c25

File tree

1 file changed

+50
-14
lines changed

1 file changed

+50
-14
lines changed

src/lib.rs

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,56 @@ trait RichRepr {
235235

236236
impl RichRepr for Channel {
237237
fn repr(&self, py: Python<'_>) -> impl IntoIterator<Item = Arg> {
238-
repr_list!(self, py,
239-
base_freq,
240-
sample_rate,
241-
length,
242-
;;
243-
delay=Time::ZERO,
244-
align_level=-10,
245-
iq_matrix=None,
246-
offset=None,
247-
fir=None,
248-
iir=None,
249-
filter_offset=false,
250-
is_real=false,
251-
)
238+
let mut result = Vec::from([
239+
Arg::pos(self.base_freq, py),
240+
Arg::pos(self.sample_rate, py),
241+
Arg::pos(self.length, py),
242+
Arg::kwd(
243+
intern!(py, "delay").clone().unbind(),
244+
self.delay,
245+
Time::ZERO,
246+
py,
247+
),
248+
Arg::kwd(
249+
intern!(py, "align_level").clone().unbind(),
250+
self.align_level,
251+
-10,
252+
py,
253+
),
254+
]);
255+
// NOTE: workaround for rich issue #3531
256+
if let Some(iq_matrix) = &self.iq_matrix {
257+
result.push(Arg::kw(
258+
intern!(py, "iq_matrix").clone().unbind(),
259+
iq_matrix,
260+
py,
261+
));
262+
}
263+
if let Some(offset) = &self.offset {
264+
result.push(Arg::kw(intern!(py, "offset").clone().unbind(), offset, py));
265+
}
266+
if let Some(iir) = &self.iir {
267+
result.push(Arg::kw(intern!(py, "iir").clone().unbind(), iir, py));
268+
}
269+
if let Some(fir) = &self.fir {
270+
result.push(Arg::kw(intern!(py, "fir").clone().unbind(), fir, py));
271+
}
272+
result.extend([
273+
Arg::kwd(
274+
intern!(py, "filter_offset").clone().unbind(),
275+
self.filter_offset,
276+
false,
277+
py,
278+
),
279+
Arg::kwd(
280+
intern!(py, "is_real").clone().unbind(),
281+
self.is_real,
282+
false,
283+
py,
284+
),
285+
]);
286+
287+
result
252288
}
253289
}
254290

0 commit comments

Comments
 (0)