-
-
Notifications
You must be signed in to change notification settings - Fork 365
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
auto_exc's hashing behavior and its documentation do not match #543
Comments
Oh god, are there any docs on Exception hashability? This looks bonkers: In [7]: hash(Exception()) == hash(Exception())
Out[7]: True
In [8]: hash(Exception(1)) == hash(Exception(1))
Out[8]: True
In [9]: hash(Exception(1)) == hash(Exception(2))
Out[9]: True
In [10]: hash(TypeError(1)) == hash(TypeError(2))
Out[10]: True |
@hynek: This confused me for quite a while, but I think I have tracked it down, helped by some further investigation by @berquist. Note you don't get the same error if you first assign the exceptions to variables before doing the comparison. I think what is going on is:
For the life of me I can't find any documentation of the requirements or conventions for The actual behavior of the built-in exceptions seems to match what the |
They now behave as the docs claim. Fixes #543
* Make auto_exc=True classes hashable by ID They now behave as the docs claim. Fixes #543 * Add PR newsfragment * Be more specific about NOP
For anyone searching for these errors, this issue can cause failures to format tracebacks that look like this: Traceback (most recent call last):
File "attrstb.py", line 19, in <module>
traceback.print_exc()
File "/usr/lib/python3.5/traceback.py", line 159, in print_exc
print_exception(*sys.exc_info(), limit=limit, file=file, chain=chain)
File "/usr/lib/python3.5/traceback.py", line 100, in print_exception
type(value), value, tb, limit=limit).format(chain=chain):
File "/usr/lib/python3.5/traceback.py", line 439, in __init__
_seen.add(exc_value)
TypeError: unhashable type: 'UnhashableException' Or, if you passed Passing @attr.s(auto_exc=True, hash=False)
class MyException(Exception):
foo = attr.ib()
|
The documentation for
auto_exc
says:However, the test for
auto_exc
says:and tests:
The documentation and the code should be made consistent. I noticed this because
unittest
complained that the exception type was unhashable when thrown from a test and I see some references tologging
expecting hashable exceptions, so the documented behavior is probably better than the implemented behavior.The text was updated successfully, but these errors were encountered: