-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Dictionary accepting Mapping in a merge operation #11264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
That would be incorrect, however, because not all mappings can be merged with a dict using the |
I don't understand what you mean with it's not part of the I was proposing a change on the |
As pointed out by Alex in #10678, static PyObject *
dict_or(PyObject *self, PyObject *other)
{
if (!PyDict_Check(self) || !PyDict_Check(other)) {
Py_RETURN_NOTIMPLEMENTED;
}
/* ... */
} The following code fails at runtime: from collections.abc import Mapping
class MyMapping(Mapping):
def __getitem__(self, i):
return 42
def __iter__(self):
return iter([42])
def __len__(self):
return 1
{} | MyMapping()
|
Thanks @srittau for explaining. |
And just in case you were looking for a workaround |
Hi. I would like to propose that a dictionary accepts a mapping to the or operation. Something like:
It would be useful in scenarios like the following:
At this point, pyright complains with
# error: Operator "|" not supported for types "dict[str, int]" and "Mapping[str, int]"
.I referenced this problem in this issue. Thanks.
The text was updated successfully, but these errors were encountered: