ipython / ipython/traitlets

CRegExp hides usefull exception when compiling pattern

オープン
#475 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
653
フォーク
217
平均マージ
2日 21時間
マージ済み PR(30日)
2

説明

Trait `CRegExp` discards the exception when compiling a regular exception, and that contains useful debugging information:
https://github.com/ipython/traitlets/blob/3164ffb43167e9d1688046fbe0aefa424af5b58d/traitlets/traitlets.py#L2883-L2889

This is the error message produced on bad regular-expressions:

the CRegExp of MyClass.regex expeted a regular expression, not the str '^('.

An obvious change to preserve the original exception would be:
```python
def validate(self, obj, value):
try:
return re.compile(value)
except Exception as ex:
self.error(obj, value, ex)
```
But unfortunately the error message becomes incomprehensible:

The 'regex' trait of a MyClass instance contains which expected , not the str 'missing ), unterminated subpattern at position 0'.

In #466 things are better (but still cannot make the TestCases to pass):

the str '^(' caused an error in the CRegExp of MyClass.regex because unknown group name 'm' at position 3.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。