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

After Pulumi 3.113.0 we started getting Never's for pulumi applied outputs in mypy #16027

Closed
rshade opened this issue Apr 22, 2024 · 1 comment · Fixed by #16139
Closed

After Pulumi 3.113.0 we started getting Never's for pulumi applied outputs in mypy #16027

rshade opened this issue Apr 22, 2024 · 1 comment · Fixed by #16139
Assignees
Labels
area/sdks Pulumi language SDKs customer/lighthouse Lighthouse customer bugs 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 Apr 22, 2024

What happened?

We upgraded an existing stack to pulumi 3.113.0 and mypy started throwing the following errors:

mypy __main__.py
__main__.py:15: error: Argument 1 to "all" of "Output" has incompatible type "Output[str]"; expected "Union[Never, Awaitable[Never], Output[Never]]"  [arg-type]
__main__.py:15: error: Argument 2 to "all" of "Output" has incompatible type "Output[bool]"; expected "Union[Never, Awaitable[Never], Output[Never]]"  [arg-type]
Found 2 errors in 1 file (checked 1 source file)

Example

"""A Random Python Pulumi program"""

from pulumi import Input, Output

should_print: Input[bool] = True
example_text: Input[str] = "hello World"


def example_print(text: str, should_print: bool) -> str:
    if should_print:
        print(text)
    return text


Output.all(Output.from_input(example_text), Output.from_input(should_print)).apply(
    lambda args: example_print(args[0], args[1])
)

Output of pulumi about

pulumi about
CLI
Version 3.113.3
Go Version go1.22.2
Go Compiler gc

Plugins
KIND NAME VERSION
resource aws 6.32.0
language python unknown
resource random 4.16.1

Host
OS ubuntu
Version 20.04
Arch x86_64

This project is written in python: version='3.8.10'

Dependencies:
NAME VERSION
mypy 1.9.0
pip 24.0
pkg_resources 0.0.0
pulumi_aws 6.32.0
pulumi_random 4.16.1
pyright 1.1.359
wheel 0.43.0

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 customer/lighthouse Lighthouse customer bugs labels Apr 22, 2024
@Frassle Frassle added area/sdks Pulumi language SDKs language/python and removed needs-triage Needs attention from the triage team labels Apr 22, 2024
@Frassle Frassle self-assigned this Apr 22, 2024
@justinvp justinvp added this to the 0.104 milestone Apr 26, 2024
@Frassle
Copy link
Member

Frassle commented May 3, 2024

Output.from_input seems to be the problem:

res1 = MyResource("testResource1")

reveal_type(res1.nested_numbers)
reveal_type(res1.nested_numbers.apply(lambda x: x))
reveal_type(res1.nested_numbers.apply(lambda x: x["foo"]))
reveal_type(Output.from_input(res1.nested_numbers))
reveal_type(Output.from_input(res1.nested_numbers).apply(lambda x: x))
lib/test/langhost/output_nested/__main__.py:48: note: Revealed type is "pulumi.output.Output[builtins.dict[Any, Any]]"
lib/test/langhost/output_nested/__main__.py:49: note: Revealed type is "pulumi.output.Output[builtins.dict[Any, Any]]"
lib/test/langhost/output_nested/__main__.py:50: note: Revealed type is "pulumi.output.Output[Any]"
lib/test/langhost/output_nested/__main__.py:51: note: Revealed type is "pulumi.output.Output[Never]"
lib/test/langhost/output_nested/__main__.py:52: note: Revealed type is "pulumi.output.Output[Never]"

Frassle added a commit that referenced this issue May 7, 2024
Fixes #16027.

Seems mypy was having issues with Outputs being passed into these methods and
tracking that they should have just been returning the same Output in the
result. Adding these extra overloads seems to have appeased the type checker
when using these methods.
Frassle added a commit that referenced this issue May 7, 2024
Fixes #16027.

Seems mypy was having issues with Outputs being passed into these methods and
tracking that they should have just been returning the same Output in the
result. Adding these extra overloads seems to have appeased the type checker
when using these methods.
github-merge-queue bot pushed a commit that referenced this issue May 7, 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

<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->

Fixes #16027.

Seems mypy was having issues with Outputs being passed into these
methods and tracking that they should have just been returning the same
Output in the result. Adding these extra overloads seems to have
appeased the type checker when using these methods.

## Checklist

- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [x] 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.
-->
- [x] 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 7, 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 customer/lighthouse Lighthouse customer bugs 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