Repository navigation
gh-149313: Preserve exception notes/cause in dict/set unhashable type… - #149505
anujbharambe wants to merge 2 commits into
Conversation
|
Updating to fix some errors we introduced on the main branch. |
|
This PR is stale because it has been open for 90 days with no activity. |
|
I looked at the duplicate-traceback concern raised in gh-149313 and tested a conditional alternative in my fork: localzet#2. The behavior is:
This addresses the traceback regression without always adding a redundant exception block for builtin unhashable objects. The experiment includes The debug build, I don't intend to open a competing upstream PR while this one is open. Would this conditional behavior fit the direction you want for gh-149313? I can help adapt the patch if useful. |
|
Thanks, @localzet. The notes-only path improves on what I suggested in gh-149313: One case to check is using try:
1/0
except ZeroDivisionError:
try:
hash(([],))
except TypeError as e:
print(repr(e.__context__)) # ZeroDivisionError('division by zero')From reading the diff, I haven't built your branch, so please correct me if I've misread it. @anujbharambe, are you still planning to continue this PR? If not, I'd be happy to prepare one with the conditional behavior. |
|
@anujbharambe, @localzet: I've opened #161536 with the conditional behavior. I asked above whether you were continuing here and didn't wait long for an answer, so I'm sorry about that. This was my first time filing an issue on a project this large, and I wanted to see this change through to a PR myself. It builds on what you both did here and in the fork experiment, and I'm happy to close it if you'd rather continue with this PR. |
|
Thanks for catching that, @WakaTaira — you're right. An ambient Please keep #161536 open. I'm happy for your PR to be the upstream implementation: it incorporates the conditional behavior, addresses the context issue, and puts the shared logic in one helper. My fork PR #2 is only a proof of concept and I won't submit a competing upstream PR. Thanks for taking this forward, and for crediting the earlier experiments. |
Summary
Chain the original
TypeErroras__cause__and__context__on the new exception indict_unhashable_type()andset_unhashable_type(). This preserves__notes__,__traceback__, and any existing cause chain that were previously discarded when the improved error message was created.Fixes #149313
Some parts of this PR were written with the assistance of Claude (AI).