From faf4d09c34f496f23ed5db51edec2d3c06e368d2 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Thu, 5 Dec 2024 11:50:02 -0600 Subject: [PATCH] scripts: Added __repr__ to RInt and friends Just a minor quality of life feature to help debugging these scripts. --- scripts/code.py | 3 +++ scripts/cov.py | 6 ++++++ scripts/csv.py | 9 +++++++++ scripts/ctx.py | 3 +++ scripts/data.py | 3 +++ scripts/perf.py | 3 +++ scripts/perfbd.py | 3 +++ scripts/stack.py | 3 +++ scripts/structs.py | 3 +++ 9 files changed, 36 insertions(+) diff --git a/scripts/code.py b/scripts/code.py index f49c6890..cd402dab 100755 --- a/scripts/code.py +++ b/scripts/code.py @@ -51,6 +51,9 @@ class RInt(co.namedtuple('RInt', 'x')): x = int(x) return super().__new__(cls, x) + def __repr__(self): + return '%s(%r)' % (self.__class__.__name__, self.x) + def __str__(self): if self.x == mt.inf: return '∞' diff --git a/scripts/cov.py b/scripts/cov.py index 11e3f54b..f02cd0e3 100755 --- a/scripts/cov.py +++ b/scripts/cov.py @@ -53,6 +53,9 @@ class RInt(co.namedtuple('RInt', 'x')): x = int(x) return super().__new__(cls, x) + def __repr__(self): + return '%s(%r)' % (self.__class__.__name__, self.x) + def __str__(self): if self.x == mt.inf: return '∞' @@ -143,6 +146,9 @@ class RFrac(co.namedtuple('RFrac', 'a,b')): b = a return super().__new__(cls, RInt(a), RInt(b)) + def __repr__(self): + return '%s(%r, %r)' % (self.__class__.__name__, self.a.x, self.b.x) + def __str__(self): return '%s/%s' % (self.a, self.b) diff --git a/scripts/csv.py b/scripts/csv.py index 82f5a7f9..1c25399a 100755 --- a/scripts/csv.py +++ b/scripts/csv.py @@ -46,6 +46,9 @@ class RInt(co.namedtuple('RInt', 'x')): x = int(x) return super().__new__(cls, x) + def __repr__(self): + return '%s(%r)' % (self.__class__.__name__, self.x) + def __str__(self): if self.x == mt.inf: return '∞' @@ -145,6 +148,9 @@ class RFloat(co.namedtuple('RFloat', 'x')): x = float(x) return super().__new__(cls, x) + def __repr__(self): + return '%s(%r)' % (self.__class__.__name__, self.x) + def __str__(self): if self.x == mt.inf: return '∞' @@ -234,6 +240,9 @@ class RFrac(co.namedtuple('RFrac', 'a,b')): b = a return super().__new__(cls, RInt(a), RInt(b)) + def __repr__(self): + return '%s(%r, %r)' % (self.__class__.__name__, self.a.x, self.b.x) + def __str__(self): return '%s/%s' % (self.a, self.b) diff --git a/scripts/ctx.py b/scripts/ctx.py index 5e911d40..ebb7cc2c 100755 --- a/scripts/ctx.py +++ b/scripts/ctx.py @@ -47,6 +47,9 @@ class RInt(co.namedtuple('RInt', 'x')): x = int(x) return super().__new__(cls, x) + def __repr__(self): + return '%s(%r)' % (self.__class__.__name__, self.x) + def __str__(self): if self.x == mt.inf: return '∞' diff --git a/scripts/data.py b/scripts/data.py index 89839b85..7f0f835d 100755 --- a/scripts/data.py +++ b/scripts/data.py @@ -51,6 +51,9 @@ class RInt(co.namedtuple('RInt', 'x')): x = int(x) return super().__new__(cls, x) + def __repr__(self): + return '%s(%r)' % (self.__class__.__name__, self.x) + def __str__(self): if self.x == mt.inf: return '∞' diff --git a/scripts/perf.py b/scripts/perf.py index a6afe381..7091fc6b 100755 --- a/scripts/perf.py +++ b/scripts/perf.py @@ -61,6 +61,9 @@ class RInt(co.namedtuple('RInt', 'x')): x = int(x) return super().__new__(cls, x) + def __repr__(self): + return '%s(%r)' % (self.__class__.__name__, self.x) + def __str__(self): if self.x == mt.inf: return '∞' diff --git a/scripts/perfbd.py b/scripts/perfbd.py index 91184037..a8718548 100755 --- a/scripts/perfbd.py +++ b/scripts/perfbd.py @@ -52,6 +52,9 @@ class RInt(co.namedtuple('RInt', 'x')): x = int(x) return super().__new__(cls, x) + def __repr__(self): + return '%s(%r)' % (self.__class__.__name__, self.x) + def __str__(self): if self.x == mt.inf: return '∞' diff --git a/scripts/stack.py b/scripts/stack.py index ee8d074b..b2a2520d 100755 --- a/scripts/stack.py +++ b/scripts/stack.py @@ -42,6 +42,9 @@ class RInt(co.namedtuple('RInt', 'x')): x = int(x) return super().__new__(cls, x) + def __repr__(self): + return '%s(%r)' % (self.__class__.__name__, self.x) + def __str__(self): if self.x == mt.inf: return '∞' diff --git a/scripts/structs.py b/scripts/structs.py index c4429b3a..411fd1d2 100755 --- a/scripts/structs.py +++ b/scripts/structs.py @@ -47,6 +47,9 @@ class RInt(co.namedtuple('RInt', 'x')): x = int(x) return super().__new__(cls, x) + def __repr__(self): + return '%s(%r)' % (self.__class__.__name__, self.x) + def __str__(self): if self.x == mt.inf: return '∞'