Skip to content

collections.abc.Sequence considered typing.Sequence #6036

Closed

Description

@AstraLuma
from collections.abc import Sequence

class Spam: pass

Sequence.register(Spam)

Produces this error when run through mypy:

test.py:5: error: "Type[Sequence[Any]]" has no attribute "register"

This is a regression in v0.650. This error was not produced in v0.641.

Activity

  1. added a commit that references this issue on Dec 9, 2018
  2. gvanrossum commented on Dec 9, 2018

    @gvanrossum
    Member

    I wonder if this is due to a change in typeshed -- I get the same error with mypy at v0.641 but typeshed at the current rev, and I don't get the error with mypy at v0.650 but typeshed at the rev it was at in the mypy 0.641 release. (I hope you follow what I'm saying here.)

    If you want to help fix this, it should be easy enough to track down the precise typeshed change using git bisect.

  3. ilevkivskyi commented on Dec 9, 2018

    @ilevkivskyi
    Member

    This is caused by PR python/typeshed#2658, for some reasons Sized was the only base that has metaclass=ABCMeta, and now it's gone. A quick solution is to put the metaclass back where it belongs.

    However, I think a better solution is automatically infer ABCMeta as a metaclass for protocols if no explicit metaclass is given in a class or its bases. The reason is that Protocol is an instance of ABCMeta at runtime, plus logically protocols are just fancier ABCs that type-checkers understand statically.

  4. ilevkivskyi commented on Dec 9, 2018

    @ilevkivskyi
    Member

    (set priority high, since this is a regression)

  5. added a commit that references this issue on Dec 10, 2018
    99d4c6b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions