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

TypeError when except* catches an unhashable exception #99181

Closed
Zac-HD opened this issue Nov 7, 2022 · 1 comment · Fixed by #99192
Closed

TypeError when except* catches an unhashable exception #99181

Zac-HD opened this issue Nov 7, 2022 · 1 comment · Fixed by #99192
Assignees
Labels
3.11 only security fixes 3.12 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@Zac-HD
Copy link
Contributor

Zac-HD commented Nov 7, 2022

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 🙂

@Zac-HD Zac-HD added the type-bug An unexpected behavior, bug, or error label Nov 7, 2022
@iritkatriel iritkatriel added 3.11 only security fixes 3.12 bugs and security fixes labels Nov 7, 2022
@iritkatriel iritkatriel self-assigned this Nov 7, 2022
@iritkatriel
Copy link
Member

Yes it’s a bug. Thanks.

@iritkatriel iritkatriel added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Nov 7, 2022
iritkatriel added a commit to iritkatriel/cpython that referenced this issue Nov 7, 2022
iritkatriel added a commit to iritkatriel/cpython that referenced this issue Nov 7, 2022
iritkatriel added a commit to iritkatriel/cpython that referenced this issue Nov 7, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 8, 2022
(cherry picked from commit c43714f)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
miss-islington added a commit that referenced this issue Nov 8, 2022
(cherry picked from commit c43714f)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants