Closed posita closed 2 years ago
That seems correct:
>>> type(os.environ | {"x": "y"})
<class 'dict'>
>>> os.environ |= {"x": "y"}
>>> type(os.environ)
<class 'os._Environ'>
It's similar to how +=
and +
are different with lists:
>>> foo = []
>>> foo + "lol"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate list (not "str") to list
>>> foo += "lol"
>>> foo
['l', 'o', 'l']
That seems correct:
…
Yeah, but I think that's a red herring. The bug is that Mypy gives a false negative for |=
. FWIW, I don't see __ior__
mentioned anywhere in os/__init__.pyi
. UPDATE: I fixed my earlier comment to hide the distraction.
Indeed, we should add an __ior__
similarly to list
's __iadd__
. It also appears to be specific to os.environ
, not inherited from its base class MutableMapping
:
>>> from collections.abc import MutableMapping
>>> MutableMapping.__ior__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: type object 'MutableMapping' has no attribute '__ior__'
>>> import os
>>> type(os.environ).__ior__
<function _Environ.__ior__ at 0x7f061ed26040>
PR welcome :)