Message355007
In the following snippet:
>>> class Ror:
... def __ror__(self, other):
... return set()
...
>>> {}.keys() | Ror()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'Ror' object is not iterable
I expect the __or__ implementation of dict_keys to return NotImplemented when given a non-interesting thing, so my __ror__ can run and get an empty set instead of a TypeError.
Strangely enough, it worked in Python 2.7, I'm not fluent enough en 2.7 object nor C implementation to know why, the dictviews_or looks the same for me.
It looks easy to fix without breaking the tests in dictobject.c like:
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -4284,7 +4284,8 @@ dictviews_or(PyObject* self, PyObject *other)
tmp = _PyObject_CallMethodIdOneArg(result, &PyId_update, other);
if (tmp == NULL) {
Py_DECREF(result);
- return NULL;
+ PyErr_Clear();
+ Py_RETURN_NOTIMPLEMENTED;
}
the question is more: should we? I think so but am I missing something? |
|
Date |
User |
Action |
Args |
2019-10-20 15:32:28 | mdk | set | recipients:
+ mdk |
2019-10-20 15:32:28 | mdk | set | messageid: <1571585548.13.0.376831813762.issue38538@roundup.psfhosted.org> |
2019-10-20 15:32:28 | mdk | link | issue38538 messages |
2019-10-20 15:32:27 | mdk | create | |
|