diff --git a/.chronus/changes/python-fallback-wire-type-unknown-encode-2026-1-9-0-0-0.md b/.chronus/changes/python-fallback-wire-type-unknown-encode-2026-1-9-0-0-0.md new file mode 100644 index 00000000000..7b70ad24f39 --- /dev/null +++ b/.chronus/changes/python-fallback-wire-type-unknown-encode-2026-1-9-0-0-0.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/http-client-python" +--- + +Fall back to wire type for unknown or unsupported encode diff --git a/packages/http-client-python/emitter/src/types.ts b/packages/http-client-python/emitter/src/types.ts index 4bffbdbb2c6..b7f6f579106 100644 --- a/packages/http-client-python/emitter/src/types.ts +++ b/packages/http-client-python/emitter/src/types.ts @@ -463,18 +463,39 @@ const sdkScalarKindToPythonKind: Record = { function emitBuiltInType( type: SdkBuiltInType | SdkDurationType | SdkDateTimeType, ): Record { - if (type.kind === "duration" && type.encode === "seconds") { - return getSimpleTypeResult({ - type: sdkScalarKindToPythonKind[type.wireType.kind], - encode: type.encode, - }); - } - if (type.encode === "unixTimestamp") { - return getSimpleTypeResult({ - type: "unixtime", - encode: type.encode, - }); + if (type.encode) { + if (type.kind === "duration") { + if (type.encode === "ISO8601") { + return getSimpleTypeResult({ + type: type.kind, + encode: type.encode, + }); + } + } + if (type.kind === "utcDateTime" || type.kind === "offsetDateTime") { + if (type.encode === "unixTimestamp") { + return getSimpleTypeResult({ + type: "unixtime", + encode: type.encode, + }); + } + if (type.encode === "rfc3339" || type.encode === "rfc7231") { + return getSimpleTypeResult({ + type: type.kind, + encode: type.encode, + }); + } + } + + // fallback to wire type for unknown or unsupported encode + if ("wireType" in type && type.wireType !== undefined) { + return getSimpleTypeResult({ + type: sdkScalarKindToPythonKind[type.wireType.kind] || type.wireType.kind, + encode: type.encode, + }); + } } + return getSimpleTypeResult({ type: sdkScalarKindToPythonKind[type.kind] || type.kind, // TODO: switch to kind encode: type.encode,