Skip to content

Add note helper? #31

@henryiii

Description

@henryiii

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions