override class function (#1418)

This commit is contained in:
Awni Hannun 2024-09-16 13:21:04 -07:00 committed by GitHub
parent 669c27140d
commit d5ed4d7a71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,18 +3,14 @@
import array
import reprlib
class FixedRepr(reprlib.Repr):
"""Only route python array instances to repr_array."""
def repr_array(self, x, maxlevel):
if isinstance(x, array.array):
return super().repr_array(x, maxlevel)
else:
return self.repr_instance(x, maxlevel)
_old_repr_array = reprlib.Repr.repr_array
# We need to monkey-patch reprlib so that we can use the debugger without
# renaming the array to something else
fixed_repr = FixedRepr()
reprlib.repr = fixed_repr.repr
def repr_array(self, x, maxlevel):
if isinstance(x, array.array):
return _old_repr_array(self, x, maxlevel)
else:
return self.repr_instance(x, maxlevel)
reprlib.Repr.repr_array = repr_array