classification
Title: Add bitwise or operator to collections.abc Mapping and MutableMapping
Type: enhancement Stage: resolved
Components: Library (Lib) Versions:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: brandtbucher, gvanrossum, uriyyo
Priority: normal Keywords: patch

Created on 2021-01-06 15:27 by uriyyo, last changed 2021-01-06 17:49 by uriyyo. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 24141 closed uriyyo, 2021-01-06 15:31
Messages (4)
msg384507 - (view) Author: Yurii Karabas (uriyyo) * (Python triager) Date: 2021-01-06 15:27
In python3.9 `dict` `bitwise or` operator was introduced.

I think it will be great if `collections.abc.Mapping` and `collections.abc.MutableMapping` will have a default implementation of `bitwise or` operator.
msg384519 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-01-06 17:31
This was discussed during the PEP review and rejected. The main reason is that this operator would need to create a new instance, and there is no standard API that's part of the Mapping protocol that can be used (the constructor of a Mapping instance might have unknown parameters).
msg384523 - (view) Author: Brandt Bucher (brandtbucher) * (Python committer) Date: 2021-01-06 17:36
(Also, it would break virtual subclasses.)
msg384527 - (view) Author: Yurii Karabas (uriyyo) * (Python triager) Date: 2021-01-06 17:49
Thanks, for the replies, didn't know about that.

Interesting thing that `collections.abc.Set` base class has implementations of `__and__`, `__or__`, `__sub__` and `__xor__` methods, it also provide `_from_iterable` class method that is used to create `Set` instance from iterable (all of those operators use this method).
```
class Set(Collection):
    ...
    @classmethod
    def _from_iterable(cls, it):
        '''Construct an instance of the class from any iterable input.

        Must override this method if the class constructor signature
        does not accept an iterable for an input.
        '''
        return cls(it)
```

Basically, my proposition was to do smth similar to `collections.abc.Mapping`, but I understand your motivation not to implement this feature.
History
Date User Action Args
2021-01-06 17:49:54uriyyosetmessages: + msg384527
2021-01-06 17:36:30brandtbuchersetnosy: + brandtbucher
messages: + msg384523
2021-01-06 17:31:28gvanrossumsetstatus: open -> closed

nosy: + gvanrossum
messages: + msg384519

resolution: wont fix
stage: patch review -> resolved
2021-01-06 15:31:21uriyyosetkeywords: + patch
stage: patch review
pull_requests: + pull_request22970
2021-01-06 15:27:47uriyyosettype: enhancement
components: + Library (Lib)
2021-01-06 15:27:26uriyyocreate