New GitHub issue #122618 from JWCS:<br>
<hr>
<pre>
https://github.com/python/cpython/blob/498376d7a7d6f704f22a2c963130cc15c17e7a6f/Lib/_collections_abc.py#L791
Relevant SO issue that still reflects this: https://stackoverflow.com/q/64503419/
``` python
class dictroproxy:
def __init__(self, d):
self._d = d
def __getitem__(self, key):
return self._d.__getitem__(key)
def __contains__(self, key):
return self._d.__contains__(key)
def __len__(self):
return self._d.__len__()
def __iter__(self):
return self._d.__iter__()
def __eq__(self, other):
if isinstance(other, dictroproxy):
other = other._d
return self._d.__eq__(other)
def __ne__(self, other):
return not self.__eq__(other)
def get(self, key, default=None):
return self._d.get(key, default)
def keys(self):
return self._d.keys()
def values(self):
return self._d.values()
def items(self):
return self._d.items()
if __name__ == "__main__":
from collections.abc import Collection, Mapping
dd = dictroproxy({"a": 1, "b": 2, "c": 3})
print("Is collection?", isinstance(dd, Collection), issubclass(dictroproxy, Collection)) # True, True
print("Is mapping?", isinstance(dd, Mapping), issubclass(dictroproxy, Mapping)) # False, False
```
It seems that a class that implements the requirements of Mapping, won't test that it is a Mapping, although it does and will satisfy the requirements and tests for a Collection.
Does this have to do with how Mapping's `__subclasshook__` is inherited from Collection? This seems to be a bug, at least for Mapping, and possibly with any similarly inherited subclasshook definitions?
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/122618">View on GitHub</a>
<p>Labels: </p>
<p>Assignee: </p>