Skip to content

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

Closed

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.

Activity

  1. gvanrossum commented on Aug 25, 2016

    @gvanrossum
    Member

    Before you ponder much more, maybe the only open PR addresses this?
    #207

  2. sixolet commented on Aug 25, 2016

    @sixolet
    Author

    Yup looks like.

  3. gvanrossum commented on Aug 25, 2016

    @gvanrossum
    Member

    Also, this looks similar: #202

  4. sixolet commented on Aug 25, 2016

    @sixolet
    Author

    Also correct. I'd close this as a duplicate.

  5. gvanrossum commented on Aug 25, 2016

    @gvanrossum
    Member

    In particular, you were apparently testing with an outdated version of typing.py. :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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