-
Notifications
You must be signed in to change notification settings - Fork 13
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
A way to express "A type which implements these N interfaces" #58
Comments
I think this is a question of broader scope than zope interfaces. In a pure python context, one could ask "how do I annotate a variable that is of a class How about defining a new interface that would inherit both class IAB(IA, IB):
...
def needs_IA_and_IB(c: IAB):
... |
This doesn't seem to work for me. Here are the full details, but in short:
If I declare I appreciate that's a convoluted and niche scenario! |
You can use classImplements like this:
|
Let's say I have two interfaces
IA
andIB
. They're completely independent of each other. I implement both in some typeC
.I can assign a
C
instance to a variable marked against either interface.I can also pass a
C
instance to a function requiring either interface.Suppose I have another function which requires both interfaces.
If I know that I'm only going to use
C
s, I can markarg: C
and call it a day.But this doesn't work if I have a second type
D
that implements both interfaces.How should I annotate
arg
? What I'd like is a way to describe "a type that implements each of these interfaces". Is there a way to do this at present? There's no notion of an intersection type; maybe there'd need to be a new Type speltImplements[IA, IB, ...]
for this purpose?Example
To give a concrete example: Twisted's
HostnameEndpoint.__init__
expects areactor
argument which should beI don't think that can be currently expressed in the type system. I'd want to spell it as something like
The inner
Union
might make things harder; even being able to express one of the two choices likewould be helpful!
I don't know if this is something in the remit of mypy-zope as opposed to the zope project itself. I'm hopingthis is a good to ask fo suggestions or feedback though!
The text was updated successfully, but these errors were encountered: