From effc959ea9087b95474ca6ea81e3b3c3f0fe372f Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 12 Nov 2024 12:02:55 -0600 Subject: [PATCH] scripts: csv.py: Improved default typechecking in RExpr Now, by default, an error is raised if any branch of an expr has an inconsistent type. This isn't always what we want. The ternary operator, for example, doesn't really care if the condition's type doesn't match the branch arms. But it's a good default, and special cases can always override the type function with their own explicit typechecking. --- scripts/csv.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/csv.py b/scripts/csv.py index 81dcb8d1..7154bcc2 100755 --- a/scripts/csv.py +++ b/scripts/csv.py @@ -346,7 +346,10 @@ class RExpr: return set(it.chain.from_iterable(v.fields() for v in self)) def type(self, types={}): - return self.a.type(types) + t = self.a.type(types) + if not all(t == v.type(types) for v in it.islice(self, 1, None)): + raise RExpr.Error("mismatched types? %r" % self) + return t def fold(self, types={}): return self.a.fold(types)