New submission from Julien Palard <[email protected]>:
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?
----------
messages: 355007
nosy: mdk
priority: normal
severity: normal
status: open
title: dictobject dictviews don't return NotImplemented for unrecognized types.
type: behavior
versions: Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue38538>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com