[Python] Why doesn't Sequence show up in list.__mro__ or list.__bases__?

Discussão em 'Python' iniciado por Stack, Setembro 17, 2025.

  1. Stack

    Stack Membro Participativo

    Consider this piece of code:

    from collections.abc import Sequence

    print(issubclass(list, Sequence)) # Output: True
    print(list.__mro__) # Output: (<class 'list'>, <class 'object'>)
    print(list.__bases__) # Output: (<class 'object'>,)


    As you can see, the first print statement establishes that list is indeed a subclass of Sequence, but when I try to enumerate its superclasses using __mro__ or __bases__, I only get object as the superclass which means there are no more superclasses higher up. Why don't __bases__ and __mro__ list Sequence as a parent class when it actually is?

    Continue reading...

Compartilhe esta Página