Skip to content

Subclasses of typing.Sequence (&c) pretend to be superclasses of all registered members of abc.Sequence (&c) #268

@sixolet

Description

@sixolet

Check this out yo:

In [1]: from typing import Sequence
In [2]: class DumbSeq(Sequence): pass
In [3]: issubclass(tuple, DumbSeq)
Out[3]: True

This has to do with the implementation of GenericMeta, where our __subclasscheck__ ends with this line:

        return issubclass(cls, self.__extra__)

And for the container classes in typing, they're defined to have the collections.abc classes as their __extra__.

Pondering a fix to suggest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions