classification
Title: frozensets should not allow the |= operator
Type: behavior Stage: resolved
Components: Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: cs-cordero, serhiy.storchaka
Priority: normal Keywords:

Created on 2020-05-20 19:28 by cs-cordero, last changed 2020-05-20 19:34 by serhiy.storchaka. This issue is now closed.

Messages (2)
msg369470 - (view) Author: Chris Cordero (cs-cordero) Date: 2020-05-20 19:28
Frozensets disallow the .update and the .__ior__ methods from being used, but allows the |= operator, which I think is inconsistent with the disallowed methods†.

```
foo = frozenset()
print(foo)             # frozenset()
foo.update({"hello"})  # AttributeError, expected
foo.__ior__({"hello"}) # AttributeError, expected
foo |= {"hello"}       # No error
print(foo)             # frozenset({"hello"})
```
msg369473 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-05-20 19:34
It is okay. In this case `a |= b` is equivalent to `a = a | b`.

The same behavior is for tuples, strings, and other non-mutable collections:

t = (1, 2)
t += (3, 4)
s = 'ab'
s += 'cd'

And even for numbers!

i = 5
i += 1
History
Date User Action Args
2020-05-20 19:34:22serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg369473

resolution: not a bug
stage: resolved
2020-05-20 19:28:14cs-corderocreate