-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Implicit TypeVar expansion of a Generic via another generic method #6933
Comments
Actually the fact that that I think it should possible to write a plugin however. You can try playing method hooks. |
Thanks for the info. I'll look into the plugin option soon. |
I started looking into how to substitute a concrete type for I found two leads:
A nudge in the right direction would be greatly appreciated! |
I think we don't have many dedicated helpers for substituting some type arguments with types. You can try playing with
Technically, you can import any module you want (just be aware of import cycles). |
@ilevkivskyi I just realized that I forgot to thank you for your advice! (I think I typed something up but never hit the 'comment' button). I have written a plugin that successfully fills in the missing TypeVar using I've hit another problem, and I'd like to know if there's another utility along the lines of There are scenarios where the def pvalue_or_callback(ctx: MethodContext) -> Type:
...
xform_type = ctx.arg_types[0][0]
xform_type_inhabited = xform_type.copy_modified(
args=xform_type.type.bases[0].args)
... That gets
Now I want to apply
Is there an easy way to do this? Thanks again! |
Hm, I don't think we have any dedicated helpers for such cases. |
I really struggled to come up with a title for this, so I apologize for the ambiguity. I also considered "Spooky TypeVar action at a distance".
I'm investigating strategies for static type checking of apache beam, which is a streaming pipeline API.
Basically, I have a generic
Transform
with an In and Out type, and another genericCollection
that wants to apply its type to the input type ofTransform
in order to produce a newCollection
with theTransform
's output type. These operations are repeated in a chain to form a pipeline:The catch is that a
Transform
's output type can be related to its input type via a TypeVar, and aCollection
contains the concrete type of that input TypeVar. So when we callCollection.apply(transform)
we want to resolve that chain of TypeVar dependencies to produce an expanded/concrete output type:The crux of the issue is here:
My naive desire was that my
Collection[builtins.str*]
would apply itsstr
type toT-1
ofTransform[T-1, Tuple[T-1, builtins.int]]
to produceCollection[Tuple[builtins.str, builtins.int]]
.Instead I get:
Is there any future universe where this is possible in mypy, or is it just too ambiguous?
Is it possible to write a mypy plugin to produce the desired result for
Collection.apply
?The text was updated successfully, but these errors were encountered: