pulumi
pulumi copied to clipboard
Output.all with multiple types throws mypy error about needing an object
What happened?
Upgrading to pulumi-3.116.0 throws an error when running mypy when you use different types in Output.all:
__main__.py:18: error: Argument 1 to "return_text" has incompatible type "object"; expected "str" [arg-type]
__main__.py:18: error: Argument 2 to "return_text" has incompatible type "object"; expected "str" [arg-type]
__main__.py:18: error: Argument 3 to "return_text" has incompatible type "object"; expected "bool" [arg-type]
Example
"""A Python Pulumi program"""
from typing import Optional
import pulumi
from pulumi import Output, Input
a: Input[str] = "Hello"
b: Input[str] = "World"
c: Optional[Input[bool]] = True
def return_text(first: str, second: str, third: bool) -> str:
return f"{first} {second} is {third}"
text = Output.all(
Output.from_input(a), Output.from_input(b), Output.from_input(c or False)
).apply(lambda x: return_text(x[0], x[1], x[2]))
print(text)```
### Output of `pulumi about`
CLI Version 3.116.0 Go Version go1.22.2 Go Compiler gc
Plugins KIND NAME VERSION language python unknown
Host OS ubuntu Version 20.04 Arch x86_64
This project is written in python: executable='venv/bin/python3' version='3.11.9'
Dependencies: NAME VERSION mypy 1.10.0 pip 24.0 pulumi 3.116.0 pyright 1.1.362
### Additional context
_No response_
### Contributing
Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).
From internal discussion, sounds like we'll likely want to add overloads up to a certain number of arguments to better model this for type checkers.
I don't think this is possible, because Output returns a list, but you can't have something like list[T1, T2, T3]. List assumes all elements are of the same type.
To have different types we need to return a tuple, but I think that would be a breaking change.
Here's an example of typing it using tuple return pyright playground
Our best option might be to weaken the all types to better match reality https://github.com/pulumi/pulumi/pull/16172/commits/d0ce289b9456474c07a347c459420a656cf79582