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

Output.all with multiple types throws mypy error about needing an object #16194

Closed
rshade opened this issue May 14, 2024 · 3 comments · Fixed by #16172
Closed

Output.all with multiple types throws mypy error about needing an object #16194

rshade opened this issue May 14, 2024 · 3 comments · Fixed by #16172
Assignees
Labels
area/sdks Pulumi language SDKs kind/bug Some behavior is incorrect or out of spec language/python resolution/fixed This issue was fixed
Milestone

Comments

@rshade
Copy link
Contributor

rshade commented May 14, 2024

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). 
@rshade rshade added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels May 14, 2024
@justinvp justinvp added area/sdks Pulumi language SDKs language/python and removed needs-triage Needs attention from the triage team labels May 14, 2024
@justinvp justinvp added this to the 0.104 milestone May 14, 2024
@justinvp
Copy link
Member

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.

@julienp
Copy link
Contributor

julienp commented May 15, 2024

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

@julienp
Copy link
Contributor

julienp commented May 15, 2024

Our best option might be to weaken the all types to better match reality d0ce289

@justinvp justinvp modified the milestones: 0.104, 0.105 May 20, 2024
github-merge-queue bot pushed a commit that referenced this issue May 23, 2024
<!--- 
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->

# Description

Pyright >= 1.1.354 assumes the typevar is Unknown if the generic class
that holds the staticmethods has no default type parameter, however in
our case the staticmethods have no link to the class's typevar.

Fixes #15914
Fixes #16194

## Checklist

- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
  - [ ] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/sdks Pulumi language SDKs kind/bug Some behavior is incorrect or out of spec language/python resolution/fixed This issue was fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants