mirror of
https://github.com/ml-explore/mlx.git
synced 2025-06-24 17:31:16 +08:00
override class function (#1418)
This commit is contained in:
parent
669c27140d
commit
d5ed4d7a71
@ -3,18 +3,14 @@
|
|||||||
import array
|
import array
|
||||||
import reprlib
|
import reprlib
|
||||||
|
|
||||||
|
_old_repr_array = reprlib.Repr.repr_array
|
||||||
|
|
||||||
class FixedRepr(reprlib.Repr):
|
|
||||||
"""Only route python array instances to repr_array."""
|
|
||||||
|
|
||||||
def repr_array(self, x, maxlevel):
|
def repr_array(self, x, maxlevel):
|
||||||
if isinstance(x, array.array):
|
if isinstance(x, array.array):
|
||||||
return super().repr_array(x, maxlevel)
|
return _old_repr_array(self, x, maxlevel)
|
||||||
else:
|
else:
|
||||||
return self.repr_instance(x, maxlevel)
|
return self.repr_instance(x, maxlevel)
|
||||||
|
|
||||||
|
|
||||||
# We need to monkey-patch reprlib so that we can use the debugger without
|
reprlib.Repr.repr_array = repr_array
|
||||||
# renaming the array to something else
|
|
||||||
fixed_repr = FixedRepr()
|
|
||||||
reprlib.repr = fixed_repr.repr
|
|
||||||
|
Loading…
Reference in New Issue
Block a user