Skip to content

Commit

Permalink
Do not generate Result types for functions with empty outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaid-Ajaj committed Dec 8, 2022
1 parent ffc01c1 commit aa8dfab
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 163 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changes:
- type: fix
scope: sdkgen/dotnet,go,nodejs,python
description: Do not generate Result types for functions with empty outputs
4 changes: 2 additions & 2 deletions pkg/codegen/dotnet/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,7 @@ func (mod *modContext) genFunction(w io.Writer, fun *schema.Function) error {
fmt.Fprintf(w, "{\n")

var typeParameter string
if fun.Outputs != nil {
if fun.Outputs != nil && len(fun.Outputs.Properties) > 0 {
typeParameter = fmt.Sprintf("<%sResult>", className)
}

Expand Down Expand Up @@ -1404,7 +1404,7 @@ func (mod *modContext) genFunction(w io.Writer, fun *schema.Function) error {
return err
}

if fun.Outputs != nil {
if fun.Outputs != nil && len(fun.Outputs.Properties) > 0 {
fmt.Fprintf(w, "\n")

res := &plainType{
Expand Down
8 changes: 4 additions & 4 deletions pkg/codegen/go/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2104,7 +2104,7 @@ func (pkg *pkgContext) genFunction(w io.Writer, f *schema.Function) error {
argsig = fmt.Sprintf("%s, args *%sArgs", argsig, name)
}
var retty string
if f.Outputs == nil {
if f.Outputs == nil || len(f.Outputs.Properties) == 0 {
retty = "error"
} else {
retty = fmt.Sprintf("(*%sResult, error)", name)
Expand All @@ -2123,7 +2123,7 @@ func (pkg *pkgContext) genFunction(w io.Writer, f *schema.Function) error {

// Now simply invoke the runtime function with the arguments.
var outputsType string
if f.Outputs == nil {
if f.Outputs == nil || len(f.Outputs.Properties) == 0 {
outputsType = "struct{}"
} else {
outputsType = name + "Result"
Expand All @@ -2134,7 +2134,7 @@ func (pkg *pkgContext) genFunction(w io.Writer, f *schema.Function) error {
fmt.Fprintf(w, "\tvar rv %s\n", outputsType)
fmt.Fprintf(w, "\terr := ctx.Invoke(\"%s\", %s, &rv, opts...)\n", f.Token, inputsVar)

if f.Outputs == nil {
if f.Outputs == nil || len(f.Outputs.Properties) == 0 {
fmt.Fprintf(w, "\treturn err\n")
} else {
// Check the error before proceeding.
Expand Down Expand Up @@ -2164,7 +2164,7 @@ func (pkg *pkgContext) genFunction(w io.Writer, f *schema.Function) error {
}
}
}
if f.Outputs != nil {
if f.Outputs != nil && len(f.Outputs.Properties) > 0 {
fmt.Fprintf(w, "\n")
fnOutputsName := pkg.functionResultTypeName(f)
pkg.genPlainType(w, fnOutputsName, f.Outputs.Comment, "", f.Outputs.Properties)
Expand Down
4 changes: 2 additions & 2 deletions pkg/codegen/nodejs/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ func (mod *modContext) genFunction(w io.Writer, fun *schema.Function) (functionF
}
info.functionArgsInterfaceName = argsInterfaceName
}
if fun.Outputs != nil {
if fun.Outputs != nil && len(fun.Outputs.Properties) > 0 {
fmt.Fprintf(w, "\n")
resultInterfaceName := title(name) + "Result"
if err := mod.genPlainType(w, resultInterfaceName, fun.Outputs.Comment, fun.Outputs.Properties, false, true, 0); err != nil {
Expand All @@ -1166,7 +1166,7 @@ func functionArgsOptional(fun *schema.Function) bool {
}

func functionReturnType(fun *schema.Function) string {
if fun.Outputs == nil {
if fun.Outputs == nil || len(fun.Outputs.Properties) == 0 {
return "void"
}
return title(tokenToFunctionName(fun.Token)) + "Result"
Expand Down
10 changes: 5 additions & 5 deletions pkg/codegen/python/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1674,14 +1674,14 @@ func (mod *modContext) genFunction(fun *schema.Function) (string, error) {
mod.genHeader(w, true /*needsSDK*/, imports)

var baseName, awaitableName string
if fun.Outputs != nil {
if fun.Outputs != nil && len(fun.Outputs.Properties) > 0 {
baseName, awaitableName = awaitableTypeNames(fun.Outputs.Token)
}
name := PyName(tokenToName(fun.Token))

// Export only the symbols we want exported.
fmt.Fprintf(w, "__all__ = [\n")
if fun.Outputs != nil {
if fun.Outputs != nil && len(fun.Outputs.Properties) > 0 {
fmt.Fprintf(w, " '%s',\n", baseName)
fmt.Fprintf(w, " '%s',\n", awaitableName)
}
Expand All @@ -1699,7 +1699,7 @@ func (mod *modContext) genFunction(fun *schema.Function) (string, error) {
// If there is a return type, emit it.
retTypeName := ""
var rets []*schema.Property
if fun.Outputs != nil {
if fun.Outputs != nil && len(fun.Outputs.Properties) > 0 {
retTypeName, rets = mod.genAwaitableType(w, fun.Outputs), fun.Outputs.Properties
fmt.Fprintf(w, "\n\n")
}
Expand All @@ -1725,7 +1725,7 @@ func (mod *modContext) genFunction(fun *schema.Function) (string, error) {

// Now simply invoke the runtime function with the arguments.
var typ string
if fun.Outputs != nil {
if fun.Outputs != nil && len(fun.Outputs.Properties) > 0 {
// Pass along the private output_type we generated, so any nested outputs classes are instantiated by
// the call to invoke.
typ = fmt.Sprintf(", typ=%s", baseName)
Expand All @@ -1734,7 +1734,7 @@ func (mod *modContext) genFunction(fun *schema.Function) (string, error) {
fmt.Fprintf(w, "\n")

// And copy the results to an object, if there are indeed any expected returns.
if fun.Outputs != nil {
if fun.Outputs != nil && len(fun.Outputs.Properties) > 0 {
fmt.Fprintf(w, " return %s(", retTypeName)
for i, ret := range rets {
if i > 0 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/codegen/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ func (fun *Function) NeedsOutputVersion() bool {
// support them and return `Task`, but there are no such
// functions in `pulumi-azure-native` or `pulumi-aws` so we
// omit to simplify.
if fun.Outputs == nil {
if fun.Outputs == nil || len(fun.Outputs.Properties) == 0 {
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ n/a

## Using funcWithEmptyOutputs {#using}

Two invocation forms are available. The direct form accepts plain
arguments and either blocks until the result value is available, or
returns a Promise-wrapped result. The output form accepts
Input-wrapped arguments and returns an Output-wrapped result.

<div>
<pulumi-chooser type="language" options="typescript,python,go,csharp,java,yaml"></pulumi-chooser>
</div>
Expand All @@ -34,8 +29,6 @@ Input-wrapped arguments and returns an Output-wrapped result.
<div class="highlight"
><pre class="chroma"><code class="language-typescript" data-lang="typescript"
><span class="k">function </span>funcWithEmptyOutputs<span class="p">(</span><span class="nx">args</span><span class="p">:</span> <span class="nx">FuncWithEmptyOutputsArgs</span><span class="p">,</span> <span class="nx">opts</span><span class="p">?:</span> <span class="nx"><a href="/docs/reference/pkg/nodejs/pulumi/pulumi/#InvokeOptions">InvokeOptions</a></span><span class="p">): Promise&lt;<span class="nx"><a href="#result">FuncWithEmptyOutputsResult</a></span>></span
><span class="k">
function </span>funcWithEmptyOutputsOutput<span class="p">(</span><span class="nx">args</span><span class="p">:</span> <span class="nx">FuncWithEmptyOutputsOutputArgs</span><span class="p">,</span> <span class="nx">opts</span><span class="p">?:</span> <span class="nx"><a href="/docs/reference/pkg/nodejs/pulumi/pulumi/#InvokeOptions">InvokeOptions</a></span><span class="p">): Output&lt;<span class="nx"><a href="#result">FuncWithEmptyOutputsResult</a></span>></span
></code></pre></div>
</pulumi-choosable>
</div>
Expand All @@ -46,9 +39,6 @@ function </span>funcWithEmptyOutputsOutput<span class="p">(</span><span class="n
<div class="highlight"><pre class="chroma"><code class="language-python" data-lang="python"
><span class="k">def </span>func_with_empty_outputs<span class="p">(</span><span class="nx">name</span><span class="p">:</span> <span class="nx">Optional[str]</span> = None<span class="p">,</span>
<span class="nx">opts</span><span class="p">:</span> <span class="nx"><a href="/docs/reference/pkg/python/pulumi/#pulumi.InvokeOptions">Optional[InvokeOptions]</a></span> = None<span class="p">) -&gt;</span> <span>FuncWithEmptyOutputsResult</span
><span class="k">
def </span>func_with_empty_outputs_output<span class="p">(</span><span class="nx">name</span><span class="p">:</span> <span class="nx">Optional[pulumi.Input[str]]</span> = None<span class="p">,</span>
<span class="nx">opts</span><span class="p">:</span> <span class="nx"><a href="/docs/reference/pkg/python/pulumi/#pulumi.InvokeOptions">Optional[InvokeOptions]</a></span> = None<span class="p">) -&gt;</span> <span>Output[FuncWithEmptyOutputsResult]</span
></code></pre></div>
</pulumi-choosable>
</div>
Expand All @@ -58,8 +48,6 @@ def </span>func_with_empty_outputs_output<span class="p">(</span><span class="nx
<pulumi-choosable type="language" values="go">
<div class="highlight"><pre class="chroma"><code class="language-go" data-lang="go"
><span class="k">func </span>FuncWithEmptyOutputs<span class="p">(</span><span class="nx">ctx</span><span class="p"> *</span><span class="nx"><a href="https://pkg.go.dev/github.com/pulumi/pulumi/sdk/v3/go/pulumi?tab=doc#Context">Context</a></span><span class="p">,</span> <span class="nx">args</span><span class="p"> *</span><span class="nx">FuncWithEmptyOutputsArgs</span><span class="p">,</span> <span class="nx">opts</span><span class="p"> ...</span><span class="nx"><a href="https://pkg.go.dev/github.com/pulumi/pulumi/sdk/v3/go/pulumi?tab=doc#InvokeOption">InvokeOption</a></span><span class="p">) (*<span class="nx"><a href="#result">FuncWithEmptyOutputsResult</a></span>, error)</span
><span class="k">
func </span>FuncWithEmptyOutputsOutput<span class="p">(</span><span class="nx">ctx</span><span class="p"> *</span><span class="nx"><a href="https://pkg.go.dev/github.com/pulumi/pulumi/sdk/v3/go/pulumi?tab=doc#Context">Context</a></span><span class="p">,</span> <span class="nx">args</span><span class="p"> *</span><span class="nx">FuncWithEmptyOutputsOutputArgs</span><span class="p">,</span> <span class="nx">opts</span><span class="p"> ...</span><span class="nx"><a href="https://pkg.go.dev/github.com/pulumi/pulumi/sdk/v3/go/pulumi?tab=doc#InvokeOption">InvokeOption</a></span><span class="p">) FuncWithEmptyOutputsResultOutput</span
></code></pre></div>
&gt; Note: This function is named `FuncWithEmptyOutputs` in the Go SDK.
Expand All @@ -72,8 +60,7 @@ func </span>FuncWithEmptyOutputsOutput<span class="p">(</span><span class="nx">c
<pulumi-choosable type="language" values="csharp">
<div class="highlight"><pre class="chroma"><code class="language-csharp" data-lang="csharp"><span class="k">public static class </span><span class="nx">FuncWithEmptyOutputs </span><span class="p">
{</span><span class="k">
public static </span>Task&lt;<span class="nx"><a href="#result">FuncWithEmptyOutputsResult</a></span>> <span class="p">InvokeAsync(</span><span class="nx">FuncWithEmptyOutputsArgs</span><span class="p"> </span><span class="nx">args<span class="p">,</span> <span class="nx"><a href="/docs/reference/pkg/dotnet/Pulumi/Pulumi.InvokeOptions.html">InvokeOptions</a></span><span class="p">? </span><span class="nx">opts = null<span class="p">)</span><span class="k">
public static </span>Output&lt;<span class="nx"><a href="#result">FuncWithEmptyOutputsResult</a></span>> <span class="p">Invoke(</span><span class="nx">FuncWithEmptyOutputsInvokeArgs</span><span class="p"> </span><span class="nx">args<span class="p">,</span> <span class="nx"><a href="/docs/reference/pkg/dotnet/Pulumi/Pulumi.InvokeOptions.html">InvokeOptions</a></span><span class="p">? </span><span class="nx">opts = null<span class="p">)</span><span class="p">
public static </span>Task&lt;<span class="nx"><a href="#result">FuncWithEmptyOutputsResult</a></span>> <span class="p">InvokeAsync(</span><span class="nx">FuncWithEmptyOutputsArgs</span><span class="p"> </span><span class="nx">args<span class="p">,</span> <span class="nx"><a href="/docs/reference/pkg/dotnet/Pulumi/Pulumi.InvokeOptions.html">InvokeOptions</a></span><span class="p">? </span><span class="nx">opts = null<span class="p">)</span><span class="p">
}</span></code></pre></div>
</pulumi-choosable>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@ public static class FuncWithEmptyOutputs
/// <summary>
/// n/a
/// </summary>
public static Task<FuncWithEmptyOutputsResult> InvokeAsync(FuncWithEmptyOutputsArgs args, InvokeOptions? options = null)
=> global::Pulumi.Deployment.Instance.InvokeAsync<FuncWithEmptyOutputsResult>("mypkg::funcWithEmptyOutputs", args ?? new FuncWithEmptyOutputsArgs(), options.WithDefaults());

/// <summary>
/// n/a
/// </summary>
public static Output<FuncWithEmptyOutputsResult> Invoke(FuncWithEmptyOutputsInvokeArgs args, InvokeOptions? options = null)
=> global::Pulumi.Deployment.Instance.Invoke<FuncWithEmptyOutputsResult>("mypkg::funcWithEmptyOutputs", args ?? new FuncWithEmptyOutputsInvokeArgs(), options.WithDefaults());
public static Task InvokeAsync(FuncWithEmptyOutputsArgs args, InvokeOptions? options = null)
=> global::Pulumi.Deployment.Instance.InvokeAsync("mypkg::funcWithEmptyOutputs", args ?? new FuncWithEmptyOutputsArgs(), options.WithDefaults());
}


Expand All @@ -38,28 +32,4 @@ public FuncWithEmptyOutputsArgs()
}
public static new FuncWithEmptyOutputsArgs Empty => new FuncWithEmptyOutputsArgs();
}

public sealed class FuncWithEmptyOutputsInvokeArgs : global::Pulumi.InvokeArgs
{
/// <summary>
/// The Name of the FeatureGroup.
/// </summary>
[Input("name", required: true)]
public Input<string> Name { get; set; } = null!;

public FuncWithEmptyOutputsInvokeArgs()
{
}
public static new FuncWithEmptyOutputsInvokeArgs Empty => new FuncWithEmptyOutputsInvokeArgs();
}


[OutputType]
public sealed class FuncWithEmptyOutputsResult
{
[OutputConstructor]
private FuncWithEmptyOutputsResult()
{
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as utilities from "./utilities";
/**
* n/a
*/
export function funcWithEmptyOutputs(args: FuncWithEmptyOutputsArgs, opts?: pulumi.InvokeOptions): Promise<FuncWithEmptyOutputsResult> {
export function funcWithEmptyOutputs(args: FuncWithEmptyOutputsArgs, opts?: pulumi.InvokeOptions): Promise<void> {

opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts || {});
return pulumi.runtime.invoke("mypkg::funcWithEmptyOutputs", {
Expand All @@ -21,19 +21,3 @@ export interface FuncWithEmptyOutputsArgs {
*/
name: string;
}

export interface FuncWithEmptyOutputsResult {
}
/**
* n/a
*/
export function funcWithEmptyOutputsOutput(args: FuncWithEmptyOutputsOutputArgs, opts?: pulumi.InvokeOptions): pulumi.Output<FuncWithEmptyOutputsResult> {
return pulumi.output(args).apply((a: any) => funcWithEmptyOutputs(a, opts))
}

export interface FuncWithEmptyOutputsOutputArgs {
/**
* The Name of the FeatureGroup.
*/
name: pulumi.Input<string>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ export const funcWithDictParam: typeof import("./funcWithDictParam").funcWithDic
export const funcWithDictParamOutput: typeof import("./funcWithDictParam").funcWithDictParamOutput = null as any;
utilities.lazyLoad(exports, ["funcWithDictParam","funcWithDictParamOutput"], () => require("./funcWithDictParam"));

export { FuncWithEmptyOutputsArgs, FuncWithEmptyOutputsResult, FuncWithEmptyOutputsOutputArgs } from "./funcWithEmptyOutputs";
export { FuncWithEmptyOutputsArgs } from "./funcWithEmptyOutputs";
export const funcWithEmptyOutputs: typeof import("./funcWithEmptyOutputs").funcWithEmptyOutputs = null as any;
export const funcWithEmptyOutputsOutput: typeof import("./funcWithEmptyOutputs").funcWithEmptyOutputsOutput = null as any;
utilities.lazyLoad(exports, ["funcWithEmptyOutputs","funcWithEmptyOutputsOutput"], () => require("./funcWithEmptyOutputs"));
utilities.lazyLoad(exports, ["funcWithEmptyOutputs"], () => require("./funcWithEmptyOutputs"));

export { FuncWithListParamArgs, FuncWithListParamResult, FuncWithListParamOutputArgs } from "./funcWithListParam";
export const funcWithListParam: typeof import("./funcWithListParam").funcWithListParam = null as any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,11 @@
from . import _utilities

__all__ = [
'FuncWithEmptyOutputsResult',
'AwaitableFuncWithEmptyOutputsResult',
'func_with_empty_outputs',
'func_with_empty_outputs_output',
]

@pulumi.output_type
class FuncWithEmptyOutputsResult:
def __init__(__self__):
pass

class AwaitableFuncWithEmptyOutputsResult(FuncWithEmptyOutputsResult):
# pylint: disable=using-constant-test
def __await__(self):
if False:
yield self
return FuncWithEmptyOutputsResult()


def func_with_empty_outputs(name: Optional[str] = None,
opts: Optional[pulumi.InvokeOptions] = None) -> AwaitableFuncWithEmptyOutputsResult:
opts: Optional[pulumi.InvokeOptions] = None):
"""
n/a
Expand All @@ -40,18 +24,5 @@ def func_with_empty_outputs(name: Optional[str] = None,
__args__ = dict()
__args__['name'] = name
opts = pulumi.InvokeOptions.merge(_utilities.get_invoke_opts_defaults(), opts)
__ret__ = pulumi.runtime.invoke('mypkg::funcWithEmptyOutputs', __args__, opts=opts, typ=FuncWithEmptyOutputsResult).value
__ret__ = pulumi.runtime.invoke('mypkg::funcWithEmptyOutputs', __args__, opts=opts).value

return AwaitableFuncWithEmptyOutputsResult()


@_utilities.lift_output_func(func_with_empty_outputs)
def func_with_empty_outputs_output(name: Optional[pulumi.Input[str]] = None,
opts: Optional[pulumi.InvokeOptions] = None) -> pulumi.Output[FuncWithEmptyOutputsResult]:
"""
n/a
:param str name: The Name of the FeatureGroup.
"""
...

0 comments on commit aa8dfab

Please sign in to comment.