This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jedwards
Recipients jedwards
Date 2019-03-28.02:40:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1553740842.38.0.441898568042.issue36455@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-03-28 02:40:42jedwardssetrecipients: + jedwards
2019-03-28 02:40:42jedwardssetmessageid: <1553740842.38.0.441898568042.issue36455@roundup.psfhosted.org>
2019-03-28 02:40:42jedwardslinkissue36455 messages
2019-03-28 02:40:42jedwardscreate