Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collections.abc.Sequence considered typing.Sequence #6036

Closed
AstraLuma opened this issue Dec 9, 2018 · 3 comments
Closed

collections.abc.Sequence considered typing.Sequence #6036

AstraLuma opened this issue Dec 9, 2018 · 3 comments
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-0-high topic-protocols

Comments

@AstraLuma
Copy link

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.

@gvanrossum
Copy link
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.

@ilevkivskyi
Copy link
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.

@ilevkivskyi ilevkivskyi added bug mypy got something wrong priority-0-high topic-protocols false-positive mypy gave an error on correct code labels Dec 9, 2018
@ilevkivskyi
Copy link
Member

(set priority high, since this is a regression)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-0-high topic-protocols
Projects
None yet
Development

No branches or pull requests

3 participants