Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(sdk): read a Python member that carries a comment

Yudhi Armyndharise85467d707f2
diff --git a/scripts/check-contract-shapes.mjs b/scripts/check-contract-shapes.mjs
index 0ad2f46b4..2fbabae5e 100644
--- a/scripts/check-contract-shapes.mjs
+++ b/scripts/check-contract-shapes.mjs
@@ -1066,7 +1066,9 @@ function parsePythonMembers(body) {
const m = t.match(/^(\w+)\s*:\s*(.+)$/);
if (!m) continue;
let optional = false;
- let typeText = m[2];
+ // A trailing comment would hide the NotRequired[...] wrapper and leave an unreadable type token,
+ // so the member read as required and its type went uncompared.
+ let typeText = m[2].replace(/\s+#.*$/, '');
const notReq = typeText.match(/^NotRequired\[(.+)\]$/s);
if (notReq) {
optional = true;
diff --git a/scripts/check-contract-shapes.spec.mjs b/scripts/check-contract-shapes.spec.mjs
index a37c52da9..3a58e7071 100644
--- a/scripts/check-contract-shapes.spec.mjs
+++ b/scripts/check-contract-shapes.spec.mjs
@@ -188,6 +188,19 @@ test('parsePythonTypes: TypedDict totals, NotRequired, aliased Literal enums, in
assert.equal(types.Session.lastError.token, 'string|null');
});
+test('parsePythonTypes: a trailing comment neither hides NotRequired nor leaves an unreadable type', () => {
+ const src = [
+ 'class Media(TypedDict):',
+ ' id: str # the media id',
+ ' data: NotRequired[str] # base64; absent when omitted (too large)',
+ ].join('\n');
+ const media = parsePythonTypes(src).Media;
+ assert.equal(media.data.optional, true);
+ assert.equal(media.data.token, 'string');
+ assert.equal(media.id.optional, false);
+ assert.equal(media.id.token, 'string');
+});
+
test('parseGoTypes: omitempty optionality, pointer nullability, const-block enums, required slices', () => {
const src = [
'type Kind string',