Skip to content

TypeError when except* catches an unhashable exception #99181

Closed

Description

@Zac-HD

I recently had pytest-dev/pytest#10466 reported, and it seems likely to be an upstream bug in except* - cc @iritkatriel fyi.
A somewhat simplified reproducing example:

class MyException(Exception):
    __hash__ = None

# Traditional try-except works fine with unhashable exceptions, e.g.:
try:
    raise ExceptionGroup("Foo", [MyException("Bar")])
except Exception:
    pass

# But here we'll get a TypeError:
try:
    raise ExceptionGroup("Foo", [MyException("Bar")])
except* Exception:
    pass
  + Exception Group Traceback (most recent call last):
  |   File "repro.py", line 12, in <module>
  |     raise ExceptionGroup("Foo", [MyException("Bar")])
  | ExceptionGroup: Foo (1 sub-exception)
  +-+---------------- 1 ----------------
    | MyException: Bar
    +------------------------------------

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "repro.py", line -1, in <module>
TypeError: unhashable type: 'MyException'

If this is the intended behavior of course we'll work around it in Pytest, but we decided to report upstream in case it's not 🙂

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Nov 7, 2022
  2. self-assigned this
    on Nov 7, 2022
  3. iritkatriel commented on Nov 7, 2022

    @iritkatriel
    Member

    Yes it’s a bug. Thanks.

  4. added 3 commits that reference this issue on Nov 7, 2022
  5. added a commit that references this issue on Nov 8, 2022
  6. added 2 commits that reference this issue on Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.11only security fixes3.12only security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions