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

ExceptionGroup PEP654 proof of concept. #3033

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AndreasBackx
Copy link

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

This is just a proof of concept for how exception groups may look, primarily looking to get some feedback on:

  1. How people would like for it to look.
  2. How the implementation should be done primarily, so feedback on the data structure changes and where to put the code.

This implementation does not (yet) care about backwards-compatibility or supportng the exceptiongroup pypi backport, that is to be added later. This is how the current example I've added looks when running,

image

Compared to the default (which is also printed below it):

image

This resolves #1859.

@AndreasBackx
Copy link
Author

@willmcgugan, when you have some time, could you share some of your critique so I can flesh this out and we can hopefully get this landed? Would like to get some early feedback before going the whole mile.

Copy link

@Zac-HD Zac-HD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really looking forward to having ExceptionGroup support in Rich! The lack of support is increasingly painful in async code.

@@ -417,6 +426,20 @@ def safe_str(_object: Any) -> str:
msg=exc_value.msg,
)


if isinstance(exc_value, BaseExceptionGroup):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be very easy to make this support older Python versions, with or without the exceptiongroup backport:

Suggested change
if isinstance(exc_value, BaseExceptionGroup):
if sys.version_info[:2] < (3, 11):
BaseExceptionGroup = getattr(sys.modules.get("exceptiongroup"), "BaseExceptionGroup", ())
if isinstance(exc_value, BaseExceptionGroup):

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was the plan but hasn't been implemented because I wanted to get a PoC out first with some feedback. See my first post as well at the bottom.

elif stack.grouped_traces:
group_exception_renderable = Panel(
Group(*[Group(*self._render_trace(console=console, options=options, trace=trace, child_index=index + 1)) for index, trace in enumerate(stack.grouped_traces)]),
title=f"[exception_group.title]{stack.exc_type} [dim]{highlighter(stack.exc_value)}",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to see support for PEP-678 __notes__ here (and in the next elif clause, for non-grouped exceptions). Probably easiest if we add a new method .render_exc_value(stack) cribbing from this part of the backport?

Copy link
Author

@AndreasBackx AndreasBackx Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also wanted to do this, but again wanted to get initial feedback first as this will depend on how the maintainer was possibly envisioning how it'd fit in the "design". If I have the go ahead for how it should be achieved, I can make the changes. Right now we're stuck waiting for feedback.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intuition as a maintainer is that fewer rounds of review makes everything easier - if I can just say "thanks, merging" that's likely to happen sooner than if we iterate. I understand not wanting to do more work which might not be merged though. 🙂

@AndreasBackx
Copy link
Author

AndreasBackx commented Jun 4, 2024

@willmcgugan, do you happen to have some time to give this a look?

Marking it as ready for review even though it was my plan to get some initial feedback first. There doesn't seem to be bandwidth and that's okay, though a quick message would be nice on what we could do to get this improved.

@AndreasBackx AndreasBackx marked this pull request as ready for review June 4, 2024 10:52
@willmcgugan
Copy link
Collaborator

Just busy ATM. I will do a pass on Rich soon. Initial impressions are that it is a good idea.

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

Successfully merging this pull request may close these issues.

[REQUEST] Support for PEP 654 tracebacks (ExceptionGroups)
3 participants