New submission from James Edwards <jh...@jheiv.com>:
Consider: from collections.abc import * class DefinitelyNotAList: def __init__(self, backer): self.backer = backer def __getitem__(self, key): return self.backer[key] def __len__(self): return len(self.backer) def __contains__(self, needle): return needle in self.backer def __reversed__(self): return reversed(self.backer) def __iter__(self): return list.__iter__(self.backer) def index(self, *args, **kwargs): return self.backer.index(*args, **kwargs) def count(self, *args, **kwargs): return self.backer.count(*args, **kwargs) dnal = DefinitelyNotAList([2,4,6,8]) for abc in [Collection, Reversible, Sized, Iterable, Container, Sequence]: print(abc.__name__.ljust(12), isinstance(dnal, abc)) Which prints: Collection True Reversible True Sized True Iterable True Container True Sequence False I'm not sure whether this is a bug, a docs bug, or just a misunderstanding but my expectation, is that, somehow, I could get isinstance(obj, Sequence) to return *without* explicitly registering it, just as True is returned for the other abcs. ---------- components: Library (Lib) messages: 339003 nosy: jedwards priority: normal severity: normal status: open title: collections.abc.Sequence doesn't support reflection/introspection versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue36455> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com