Skip to content

@implements(Protocol) decorator possible without Higher Kinded Types? #1943

Answered by Daverball
randolf-scholz asked this question in Q&A
Discussion options

You must be logged in to vote

Indeed, this does appear impossible without HKTs or a dedicated mypy plugin, like mypy-zope which does provide support for zope.interface's Interface objects as types and its @implementer decorator.

But it seems to me like first-class support for a decorator like this seems preferable over a generic approach using HKTs, purely due to the quality of the error messages you're likely to get out of it. Like a non-generic version of this currently does:

Value of type variable "T" of "implements" cannot be "type[Bar]"  [type-var]

It doesn't tell you what attributes/methods are missing or incorrect, so not very helpful at all. Although to be fair, it also doesn't tell you in an x: type[Proto] =…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by randolf-scholz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants