microsoft/aspire · error · TypeError

Unexpected keyword arguments

Error message

Unexpected keyword arguments: {list(kwargs.keys())}

What it means

The generated Python resource constructors accept **kwargs for forwarding to the parent class; for base resource classes (which have no parent to forward to), any leftover kwargs indicate a misuse, so generated code raises TypeError 'Unexpected keyword arguments: {list(kwargs.keys())}'. This surfaces typos or unsupported options passed to generated resource constructors.

Solutions

  1. Remove the unexpected keyword arguments from the constructor call.
  2. Call the correct subclass whose constructor supports the option.
  3. Regenerate the Python client so the constructor signature is current.
  4. Check the generated class's __init__ signature to see accepted parameters.

Example fix

# before
app.add(MyResource(handle, client, name="x"))  # name not accepted by base
# after
app.add(MyResource(handle, client))
Defensive patterns

Strategy: try-catch

Validate before calling

if kwargs:
    raise TypeError(f"Unexpected keyword arguments: {list(kwargs.keys())}")

Try / catch

except TypeError as e:
    # inspect message for the offending kwarg names and fix the call site

Prevention

When it happens

Trigger: Instantiating a generated base resource class with any keyword argument not consumed explicitly (handle/client), e.g. MyClass(handle, client, name="x").

Common situations: Typos in keyword names; copying constructor args from a subclass to its base class; calling a subclass-only option on the base class; stale generated code missing a newer parameter.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/4edea0b8a88836e7. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.CodeGeneration.Python/AtsPythonCodeGenerator.cs:1646

        var methods = builder.Capabilities.Where(c =>
            c.CapabilityKind != AtsCapabilityKind.PropertyGetter &&
            c.CapabilityKind != AtsCapabilityKind.PropertySetter &&
            !IsTargetTypeCoveredByBaseHierarchy(c.TargetType, builder.TargetType)).ToList();

        methods = MergeCapabilitiesBySourceLocation(methods);

        foreach (var capability in methods)
        {
            GenerateBuilderMethod(sb, capability, false, sbOptions, sbConstructor, builder.BuilderClassName);
            sb.AppendLine();
        }

        if (isBaseResource)
        {
            sbConstructor.AppendLine("        self._handle = handle");
            sbConstructor.AppendLine("        self._client = client");
            sbConstructor.AppendLine("        if kwargs:");
            sbConstructor.AppendLine("            raise TypeError(f\"Unexpected keyword arguments: {list(kwargs.keys())}\")");
        }
        else
        {
            sbConstructor.AppendLine("        super().__init__(handle, client, **kwargs)");
        }
        sb.AppendLine(sbConstructor.ToString());
    }

    private void GenerateBuilderMethod(System.Text.StringBuilder sb, AtsCapabilityInfo capability, bool isInterface,
        System.Text.StringBuilder? options = null, System.Text.StringBuilder? constructor = null, string? builderClassName = null)
    {
        var methodName = GetPythonMethodName(capability.MethodName);
        // Use the actual target parameter name from the capability
        var targetParamName = capability.TargetParameterName ?? "builder";
        var userParams = FilterMethodParameters(capability.Parameters, targetParamName);

        // Determine return type - use the builder's own type for fluent methods
        var returnsBuilder = capability.ReturnsBuilder && capability.ReturnType!.TypeId == capability.TargetTypeId;

View on GitHub (pinned to 25830f84bd)