cloud-custodian / cloud-custodian/cel-python

Challenging to diagnose bad expressions when using numerical comparison operators.

未关闭
#123 5 条评论 1 个 reaction 已指派 1 人 已被 @klarose 认领 在 GitHub 查看
enhancement
主要语言
Python
星标
174
派生
40
PR 合并指标
30 天内没有已合并 PR

描述

I have an expression where one side of a comparison operator fails (e.g. undeclared reference). The result is a "no matching overload" error, which isn't very helpful. I expect to see the original failure bubble up to the top of the evaluation.

E.g.

```
python3 -m celpy -n 'bad < 113.0'
ERROR: :1:1 found no matching overload for 'relation_lt' applied to '(, )'
| bad < 113.0
| ^
```

While the offending part of the expression is still in the output, it's still fairly misleading, and could cause code trying to customize error handling to do the wrong thing.

I took a quick gander where the failure occurs, and it seems to be that the builtin comparison operators don't have an overload for the CELEvalError class. Many of the others do. I'm not sure if this was a miss or on purpose.

Either way, hacking this in seemed to fix the problem:

```
diff --git a/src/celpy/evaluation.py b/src/celpy/evaluation.py
index 799b05c..8545a02 100644
--- a/src/celpy/evaluation.py
+++ b/src/celpy/evaluation.py
@@ -228,10 +228,22 @@ class CELEvalError(Exception):
def __rpow__(self, other: Any) -> "CELEvalError":
return self

+ def __lt__(self, other: Any) -> "CELEvalError":
+ raise self
+
+ def __le__(self, other: Any) -> "CELEvalError":
+ raise self
+
+ def __gt__(self, other: Any) -> "CELEvalError":
+ raise self
+
+ def __ge__(self, other: Any) -> "CELEvalError":
+ raise self
+
def __eq__(self, other: Any) -> bool:
if isinstance(other, CELEvalError):
return self.args == other.args
- return NotImplemented
+ raise self

def __call__(self, *args: Any) -> "CELEvalError":
return self
```

I can submit a PR if there's interest.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。