From 5d8932ccedd15b191089af9fd69100e0ccc62015 Mon Sep 17 00:00:00 2001 From: Mauricio Gardini Date: Fri, 20 Feb 2026 22:57:11 +0000 Subject: [PATCH] Make callStatementVar to not create symbols --- .../src/components/VariableDeclaration.tsx | 45 ++++++++++---- .../test/functioncallexpressions.test.tsx | 59 +++++++++++++++++++ 2 files changed, 93 insertions(+), 11 deletions(-) diff --git a/packages/python/src/components/VariableDeclaration.tsx b/packages/python/src/components/VariableDeclaration.tsx index 0e352ae32..3fa2b31f1 100644 --- a/packages/python/src/components/VariableDeclaration.tsx +++ b/packages/python/src/components/VariableDeclaration.tsx @@ -6,6 +6,7 @@ import { createSymbolSlot, memo, } from "@alloy-js/core"; +import { usePythonNamePolicy } from "../name-policy.js"; import { createPythonSymbol } from "../symbol-creation.js"; import { Atom } from "./Atom.jsx"; import { BaseDeclarationProps } from "./Declaration.jsx"; @@ -74,17 +75,20 @@ export function VariableDeclaration(props: VariableDeclarationProps) { const TypeSymbolSlot = createSymbolSlot(); const ValueTypeSymbolSlot = createSymbolSlot(); - const sym = createPythonSymbol( - props.name, - { - instance: props.instanceVariable, - refkeys: props.refkey, - type: props.type ? TypeSymbolSlot.firstSymbol : undefined, - }, - "variable", - ); + // For callStatementVar, don't create a symbol (keyword arguments aren't variables) + const sym = props.callStatementVar + ? undefined + : createPythonSymbol( + props.name, + { + instance: props.instanceVariable, + refkeys: props.refkey, + type: props.type ? TypeSymbolSlot.firstSymbol : undefined, + }, + "variable", + ); - if (!props.type) { + if (!props.type && sym) { ValueTypeSymbolSlot.moveMembersTo(sym); } @@ -133,13 +137,32 @@ export function VariableDeclaration(props: VariableDeclarationProps) { ]; }; const [renderRightSideOperator, rightSide] = getRightSide(); + + // For callStatementVar, render without symbol registration + // We need to manually apply the name policy to the name + // since that is normally handled by the symbol creation. + if (props.callStatementVar) { + const namePolicy = usePythonNamePolicy(); + const name = + typeof props.name === "string" && props.name + ? namePolicy.getName(props.name, "variable") + : ""; + return ( + <> + {name} + {renderRightSideOperator && assignmentOperator} + {rightSide} + + ); + } + return ( <> - + {} {type} {renderRightSideOperator && assignmentOperator} diff --git a/packages/python/test/functioncallexpressions.test.tsx b/packages/python/test/functioncallexpressions.test.tsx index 531668f34..4984c3cbd 100644 --- a/packages/python/test/functioncallexpressions.test.tsx +++ b/packages/python/test/functioncallexpressions.test.tsx @@ -142,4 +142,63 @@ describe("FunctionCallExpression", () => { `; expect(result).toRenderTo(expected); }); + + it("keyword argument name does not conflict with same-named variable", () => { + const resKey = refkey(); + const kwargsKey = refkey(); + const result = toSourceText([ + + } /> + Operation.QUERY} + callStatementVar + />, + , + , + ]} + /> + } + /> + + + + + } + /> + , + ]); + const expected = d` + kwargs = {} + res = resolve_with_adapter( + obj, + info, + operation=Operation.QUERY, + data=kwargs, + is_v5=True + ) + data = res["data"] + `; + expect(result).toRenderTo(expected); + }); });