{"record":{"id":"4edea0b8a88836e7","repo":"microsoft/aspire","slug":"unexpected-keyword-arguments-list-kwargs-keys","errorCode":null,"errorMessage":"Unexpected keyword arguments: {list(kwargs.keys())}","messagePattern":"Unexpected keyword arguments: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.CodeGeneration.Python/AtsPythonCodeGenerator.cs","lineNumber":1646,"sourceCode":"        var methods = builder.Capabilities.Where(c =>\n            c.CapabilityKind != AtsCapabilityKind.PropertyGetter &&\n            c.CapabilityKind != AtsCapabilityKind.PropertySetter &&\n            !IsTargetTypeCoveredByBaseHierarchy(c.TargetType, builder.TargetType)).ToList();\n\n        methods = MergeCapabilitiesBySourceLocation(methods);\n\n        foreach (var capability in methods)\n        {\n            GenerateBuilderMethod(sb, capability, false, sbOptions, sbConstructor, builder.BuilderClassName);\n            sb.AppendLine();\n        }\n\n        if (isBaseResource)\n        {\n            sbConstructor.AppendLine(\"        self._handle = handle\");\n            sbConstructor.AppendLine(\"        self._client = client\");\n            sbConstructor.AppendLine(\"        if kwargs:\");\n            sbConstructor.AppendLine(\"            raise TypeError(f\\\"Unexpected keyword arguments: {list(kwargs.keys())}\\\")\");\n        }\n        else\n        {\n            sbConstructor.AppendLine(\"        super().__init__(handle, client, **kwargs)\");\n        }\n        sb.AppendLine(sbConstructor.ToString());\n    }\n\n    private void GenerateBuilderMethod(System.Text.StringBuilder sb, AtsCapabilityInfo capability, bool isInterface,\n        System.Text.StringBuilder? options = null, System.Text.StringBuilder? constructor = null, string? builderClassName = null)\n    {\n        var methodName = GetPythonMethodName(capability.MethodName);\n        // Use the actual target parameter name from the capability\n        var targetParamName = capability.TargetParameterName ?? \"builder\";\n        var userParams = FilterMethodParameters(capability.Parameters, targetParamName);\n\n        // Determine return type - use the builder's own type for fluent methods\n        var returnsBuilder = capability.ReturnsBuilder && capability.ReturnType!.TypeId == capability.TargetTypeId;","sourceCodeStart":1628,"sourceCodeEnd":1664,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.CodeGeneration.Python/AtsPythonCodeGenerator.cs#L1628-L1664","documentation":"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.","triggerScenarios":"Instantiating a generated base resource class with any keyword argument not consumed explicitly (handle/client), e.g. MyClass(handle, client, name=\"x\").","commonSituations":"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.","solutions":["Remove the unexpected keyword arguments from the constructor call.","Call the correct subclass whose constructor supports the option.","Regenerate the Python client so the constructor signature is current.","Check the generated class's __init__ signature to see accepted parameters."],"exampleFix":"# before\napp.add(MyResource(handle, client, name=\"x\"))  # name not accepted by base\n# after\napp.add(MyResource(handle, client))","handlingStrategy":"try-catch","validationCode":"if kwargs:\n    raise TypeError(f\"Unexpected keyword arguments: {list(kwargs.keys())}\")","typeGuard":null,"tryCatchPattern":"except TypeError as e:\n    # inspect message for the offending kwarg names and fix the call site","preventionTips":["Inspect generated __init__ signatures before passing extra kwargs.","Regenerate clients after AppHost changes.","Forward subclass-only options to the right subclass, not the base."],"tags":["python","generated-code","type-error","keyword-arguments"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}