Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add note helper? #31

Open
henryiii opened this issue Oct 11, 2022 · 1 comment
Open

Add note helper? #31

henryiii opened this issue Oct 11, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@henryiii
Copy link

Just curious, I find myself using:

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:

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)
@agronholm
Copy link
Owner

I'll think about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants