Skip to content

Commit

Permalink
Weaken Output.all types
Browse files Browse the repository at this point in the history
The previous types stated that all the arguments to `Output.all` should
be of the same type, however you can pass through a list of mixed types.

If `Output.all` returned a tuple isntead, we could provide overloads
that returned a `Output[tuple[T1, T2, ...]]` with the precise types.
With the return type being a list, we are limited to `List[Any]`.
  • Loading branch information
julienp committed May 15, 2024
1 parent 59ba669 commit d0ce289
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- type: fix
scope: sdk/python
description: Relax Output.all types to better match the implementation
12 changes: 7 additions & 5 deletions sdk/python/lib/pulumi/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,22 +437,24 @@ def secret(val: Input[U]) -> "Output[U]":
# https://mypy.readthedocs.io/en/stable/more_types.html#type-checking-the-variants:~:text=considered%20unsafely%20overlapping
@overload
@staticmethod
def all(*args: "Output[U]") -> "Output[List[U]]": ... # type: ignore
def all(*args: "Output[Any]") -> "Output[List[Any]]": ... # type: ignore

@overload
@staticmethod
def all(**kwargs: "Output[U]") -> "Output[Dict[str, U]]": ... # type: ignore
def all(**kwargs: "Output[Any]") -> "Output[Dict[str, Any]]": ... # type: ignore

@overload
@staticmethod
def all(*args: Input[U]) -> "Output[List[U]]": ... # type: ignore
def all(*args: Input[Any]) -> "Output[List[Any]]": ... # type: ignore

@overload
@staticmethod
def all(**kwargs: Input[U]) -> "Output[Dict[str, U]]": ... # type: ignore
def all(**kwargs: Input[Any]) -> "Output[Dict[str, Any]]": ... # type: ignore

@staticmethod
def all(*args: Input[U], **kwargs: Input[U]) -> "Output[list[U] | dict[str, U]]":
def all(
*args: Input[Any], **kwargs: Input[Any]
) -> "Output[list[Any] | dict[str, Any]]":
"""
Produces an Output of a list (if args i.e a list of inputs are supplied)
or dict (if kwargs i.e. keyworded arguments are supplied).
Expand Down

0 comments on commit d0ce289

Please sign in to comment.