Message276533
If __eq__() raise an exception, _PyDict_GetItem_KnownHash() currently returns NULL and pass through the exception. To me, it looks like the correct behaviour.
With your patch, it looks like the _PyDict_GetItem_KnownHash() clears the __eq__() exception: return NULL with no exception set, as if the key is simply missing.
PyDict_GetItem() ignores *almost* all exceptions, but for bad reasons:
/* Note that, for historical reasons, PyDict_GetItem() suppresses all errors
* that may occur (originally dicts supported only string keys, and exceptions
* weren't possible). (...) */
I would prefer to not ignore __eq__ exceptions, but pass them through.
To be clear: this is a behaviour change compared to Python 3.5 which works as PyDict_GetItem(), ignore *all* exceptions:
ep = (mp->ma_keys->dk_lookup)(mp, key, hash, &value_addr);
if (ep == NULL) {
PyErr_Clear();
return NULL;
}
I consider that it's ok to change _PyDict_GetItem_KnownHash() behaviour because this function is private and only used 4 times in 250k lines of C code.
Would you be interested to write a different patch to pass through the exception?
Note: It seems like _count_elements() (Modules/_collectionsmodule.c) doesn't handle correctly such error. |
|
Date |
User |
Action |
Args |
2016-09-15 08:34:53 | vstinner | set | recipients:
+ vstinner, methane, xiang.zhang |
2016-09-15 08:34:53 | vstinner | set | messageid: <1473928493.03.0.159804968325.issue28123@psf.upfronthosting.co.za> |
2016-09-15 08:34:53 | vstinner | link | issue28123 messages |
2016-09-15 08:34:52 | vstinner | create | |
|