agronholm / agronholm/exceptiongroup

Add note helper?

未關閉
#31 1 則留言 3 個 reaction 已指派 0 人 在 GitHub 檢視
enhancement
主要語言
Python
星號
49
分支
23
PR 合併指標
30 天內沒有已合併 PR

描述

Just curious, I find myself using:

```python
if sys.version_info < (3, 11):
err.__notes__ = getattr(err, "__notes__", []) + [msg] # type: ignore[attr-defined]
else:
err.add_note(msg) # pylint: disable=no-member
```

in order to add notes to the exceptions contained in the exception group. (See cattrs, where I got the idea from). There's already a helper function (`exceptiongroup.catch()`), would an `add_note()` helper be helpful and in scope?

This would be the definition, I think:

```python
def add_note(err: BaseException, msg: str) -> None:
if sys.version_info < (3, 11):
err.__notes__ = getattr(err, "__notes__", []) + [msg]
else:
err.add_note(msg)
```

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。