Author mdk
Recipients mdk
Date 2019-10-20.15:32:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1571585548.13.0.376831813762.issue38538@roundup.psfhosted.org>
In-reply-to
Content
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?
History
Date User Action Args
2019-10-20 15:32:28mdksetrecipients: + mdk
2019-10-20 15:32:28mdksetmessageid: <1571585548.13.0.376831813762.issue38538@roundup.psfhosted.org>
2019-10-20 15:32:28mdklinkissue38538 messages
2019-10-20 15:32:27mdkcreate