@alloy-js/python 0.1.0-dev.4 → 0.1.0-dev.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/dist/src/components/CallSignature.d.ts.map +1 -1
  2. package/dist/src/components/CallSignature.js +8 -11
  3. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  4. package/dist/src/components/ClassDeclaration.js +6 -20
  5. package/dist/src/components/ClassInstantiation.d.ts.map +1 -1
  6. package/dist/src/components/ClassInstantiation.js +4 -4
  7. package/dist/src/components/Declaration.d.ts +1 -5
  8. package/dist/src/components/Declaration.d.ts.map +1 -1
  9. package/dist/src/components/Declaration.js +6 -15
  10. package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
  11. package/dist/src/components/EnumDeclaration.js +33 -59
  12. package/dist/src/components/EnumMember.d.ts.map +1 -1
  13. package/dist/src/components/EnumMember.js +3 -4
  14. package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
  15. package/dist/src/components/FunctionDeclaration.js +6 -15
  16. package/dist/src/components/LexicalScope.d.ts +8 -0
  17. package/dist/src/components/LexicalScope.d.ts.map +1 -0
  18. package/dist/src/components/LexicalScope.js +21 -0
  19. package/dist/src/components/MemberScope.d.ts +8 -0
  20. package/dist/src/components/MemberScope.d.ts.map +1 -0
  21. package/dist/src/components/MemberScope.js +15 -0
  22. package/dist/src/components/SourceFile.js +1 -2
  23. package/dist/src/components/VariableDeclaration.d.ts.map +1 -1
  24. package/dist/src/components/VariableDeclaration.js +8 -31
  25. package/dist/src/components/index.d.ts +2 -0
  26. package/dist/src/components/index.d.ts.map +1 -1
  27. package/dist/src/components/index.js +2 -0
  28. package/dist/src/create-module.d.ts.map +1 -1
  29. package/dist/src/create-module.js +3 -4
  30. package/dist/src/name-conflict-resolver.d.ts +3 -0
  31. package/dist/src/name-conflict-resolver.d.ts.map +1 -0
  32. package/dist/src/name-conflict-resolver.js +7 -0
  33. package/dist/src/symbol-creation.d.ts +13 -2
  34. package/dist/src/symbol-creation.d.ts.map +1 -1
  35. package/dist/src/symbol-creation.js +33 -9
  36. package/dist/src/symbols/index.d.ts +1 -1
  37. package/dist/src/symbols/index.d.ts.map +1 -1
  38. package/dist/src/symbols/index.js +1 -1
  39. package/dist/src/symbols/python-lexical-scope.d.ts +7 -0
  40. package/dist/src/symbols/python-lexical-scope.d.ts.map +1 -0
  41. package/dist/src/symbols/python-lexical-scope.js +14 -0
  42. package/dist/src/symbols/python-member-scope.d.ts +3 -4
  43. package/dist/src/symbols/python-member-scope.d.ts.map +1 -1
  44. package/dist/src/symbols/python-member-scope.js +4 -7
  45. package/dist/src/symbols/python-module-scope.d.ts +4 -9
  46. package/dist/src/symbols/python-module-scope.d.ts.map +1 -1
  47. package/dist/src/symbols/python-module-scope.js +6 -14
  48. package/dist/src/symbols/python-output-symbol.d.ts +10 -7
  49. package/dist/src/symbols/python-output-symbol.d.ts.map +1 -1
  50. package/dist/src/symbols/python-output-symbol.js +23 -6
  51. package/dist/src/symbols/reference.d.ts +2 -2
  52. package/dist/src/symbols/reference.d.ts.map +1 -1
  53. package/dist/src/symbols/reference.js +36 -36
  54. package/dist/src/symbols/scopes.d.ts +3 -1
  55. package/dist/src/symbols/scopes.d.ts.map +1 -1
  56. package/dist/src/symbols/scopes.js +8 -0
  57. package/dist/test/classdeclarations.test.js +87 -52
  58. package/dist/test/enums.test.js +8 -2
  59. package/dist/test/externals.test.js +6 -5
  60. package/dist/test/functiondeclaration.test.js +73 -36
  61. package/dist/test/imports.test.js +9 -36
  62. package/dist/test/utils.d.ts +2 -3
  63. package/dist/test/utils.d.ts.map +1 -1
  64. package/dist/test/utils.js +3 -2
  65. package/dist/test/variables.test.js +11 -11
  66. package/dist/tsconfig.tsbuildinfo +1 -1
  67. package/package.json +2 -2
  68. package/src/components/CallSignature.tsx +9 -17
  69. package/src/components/ClassDeclaration.tsx +5 -32
  70. package/src/components/ClassInstantiation.tsx +6 -12
  71. package/src/components/Declaration.tsx +1 -20
  72. package/src/components/EnumDeclaration.tsx +18 -41
  73. package/src/components/EnumMember.tsx +1 -3
  74. package/src/components/FunctionDeclaration.tsx +5 -24
  75. package/src/components/LexicalScope.tsx +24 -0
  76. package/src/components/MemberScope.tsx +18 -0
  77. package/src/components/SourceFile.tsx +2 -2
  78. package/src/components/VariableDeclaration.tsx +7 -35
  79. package/src/components/index.ts +2 -0
  80. package/src/create-module.ts +7 -13
  81. package/src/name-conflict-resolver.ts +21 -0
  82. package/src/symbol-creation.ts +50 -11
  83. package/src/symbols/index.ts +1 -1
  84. package/src/symbols/python-lexical-scope.ts +16 -0
  85. package/src/symbols/python-member-scope.ts +4 -8
  86. package/src/symbols/python-module-scope.ts +6 -32
  87. package/src/symbols/python-output-symbol.ts +36 -10
  88. package/src/symbols/reference.tsx +70 -0
  89. package/src/symbols/scopes.ts +15 -1
  90. package/temp/api.json +897 -539
  91. package/test/classdeclarations.test.tsx +66 -31
  92. package/test/enums.test.tsx +2 -2
  93. package/test/externals.test.tsx +6 -7
  94. package/test/functiondeclaration.test.tsx +48 -39
  95. package/test/imports.test.tsx +11 -36
  96. package/test/utils.tsx +9 -5
  97. package/test/variables.test.tsx +11 -7
  98. package/dist/src/symbols/custom-output-scope.d.ts +0 -10
  99. package/dist/src/symbols/custom-output-scope.d.ts.map +0 -1
  100. package/dist/src/symbols/custom-output-scope.js +0 -25
  101. package/src/symbols/custom-output-scope.ts +0 -35
  102. package/src/symbols/reference.ts +0 -99
@@ -32,9 +32,15 @@ describe("Python Class", () => {
32
32
  const result = toSourceText([_$createComponent(py.StatementList, {
33
33
  get children() {
34
34
  return [_$createComponent(py.ClassDeclaration, {
35
- name: "Base1"
35
+ name: "Base1",
36
+ get refkey() {
37
+ return refkey("Base1");
38
+ }
36
39
  }), _$createComponent(py.ClassDeclaration, {
37
- name: "Base2"
40
+ name: "Base2",
41
+ get refkey() {
42
+ return refkey("Base2");
43
+ }
38
44
  }), _$createComponent(py.ClassDeclaration, {
39
45
  name: "Baz",
40
46
  get bases() {
@@ -75,7 +81,10 @@ describe("Python Class", () => {
75
81
  path: "mod1.py",
76
82
  get children() {
77
83
  return _$createComponent(py.ClassDeclaration, {
78
- name: "A"
84
+ name: "A",
85
+ get refkey() {
86
+ return refkey("A");
87
+ }
79
88
  });
80
89
  }
81
90
  }), _$createComponent(py.SourceFile, {
@@ -83,6 +92,9 @@ describe("Python Class", () => {
83
92
  get children() {
84
93
  return _$createComponent(py.ClassDeclaration, {
85
94
  name: "B",
95
+ get refkey() {
96
+ return refkey("B");
97
+ },
86
98
  get bases() {
87
99
  return [refkey("A")];
88
100
  }
@@ -135,7 +147,10 @@ describe("Python Class", () => {
135
147
  const result = toSourceText([_$createComponent(py.StatementList, {
136
148
  get children() {
137
149
  return [_$createComponent(py.ClassDeclaration, {
138
- name: "A"
150
+ name: "A",
151
+ get refkey() {
152
+ return refkey("A");
153
+ }
139
154
  }), _$createComponent(py.ClassDeclaration, {
140
155
  name: "B",
141
156
  get children() {
@@ -171,6 +186,8 @@ describe("Python Class", () => {
171
186
  expect(result).toRenderTo(expected);
172
187
  });
173
188
  it("renders a class with class variables like foo: str, and another identical class", () => {
189
+ const fooKey = refkey();
190
+ const barKey = refkey();
174
191
  const result = toSourceText([_$createComponent(py.StatementList, {
175
192
  get children() {
176
193
  return [_$createComponent(py.ClassDeclaration, {
@@ -181,6 +198,7 @@ describe("Python Class", () => {
181
198
  return _$createComponent(py.VariableDeclaration, {
182
199
  name: "foo",
183
200
  type: "str",
201
+ refkey: fooKey,
184
202
  omitNone: true
185
203
  });
186
204
  }
@@ -194,12 +212,13 @@ describe("Python Class", () => {
194
212
  return _$createComponent(py.VariableDeclaration, {
195
213
  name: "foo",
196
214
  type: "str",
215
+ refkey: barKey,
197
216
  omitNone: true
198
217
  });
199
218
  }
200
219
  });
201
220
  }
202
- })];
221
+ }), fooKey, barKey];
203
222
  }
204
223
  })]);
205
224
  const expected = d`
@@ -209,7 +228,8 @@ describe("Python Class", () => {
209
228
  class B:
210
229
  foo: str
211
230
 
212
-
231
+ A.foo
232
+ B.foo
213
233
  `;
214
234
  expect(result).toRenderTo(expected);
215
235
  });
@@ -219,22 +239,32 @@ describe("Python Class - VariableDeclaration", () => {
219
239
  const result = toSourceText([_$createComponent(py.StatementList, {
220
240
  get children() {
221
241
  return [_$createComponent(py.ClassDeclaration, {
242
+ get refkey() {
243
+ return refkey("Base");
244
+ },
222
245
  name: "Base"
223
246
  }), _$createComponent(py.ClassDeclaration, {
247
+ get refkey() {
248
+ return refkey("A");
249
+ },
224
250
  name: "A",
225
251
  get children() {
226
252
  return _$createComponent(py.StatementList, {
227
253
  get children() {
228
254
  return [_$createComponent(py.VariableDeclaration, {
255
+ instanceVariable: true,
229
256
  name: "just_name"
230
257
  }), _$createComponent(py.VariableDeclaration, {
258
+ instanceVariable: true,
231
259
  name: "name_and_type",
232
260
  type: "number"
233
261
  }), _$createComponent(py.VariableDeclaration, {
262
+ instanceVariable: true,
234
263
  name: "name_type_and_value",
235
264
  type: "number",
236
265
  initializer: 12
237
266
  }), _$createComponent(py.VariableDeclaration, {
267
+ instanceVariable: true,
238
268
  name: "class_based",
239
269
  get type() {
240
270
  return refkey("Base");
@@ -275,14 +305,8 @@ describe("Python Class - VariableDeclaration", () => {
275
305
  refkey: v1Rk,
276
306
  type: classRk,
277
307
  get initializer() {
278
- return _$createComponent(py.MemberExpression, {
279
- get children() {
280
- return [_$createComponent(py.MemberExpression.Part, {
281
- refkey: classRk
282
- }), _$createComponent(py.MemberExpression.Part, {
283
- args: true
284
- })];
285
- }
308
+ return _$createComponent(py.ClassInstantiation, {
309
+ target: classRk
286
310
  });
287
311
  }
288
312
  }), [_$memo(() => memberRefkey(v1Rk, classMemberRk))], [_$memo(() => memberRefkey(v1Rk, classMethodRk)), "()"]];
@@ -336,46 +360,56 @@ describe("Python Class - VariableDeclaration", () => {
336
360
  });
337
361
  describe("Python Class - FunctionDeclaration", () => {
338
362
  it("renders a class with class fields and method", () => {
339
- const result = toSourceText([[_$createComponent(py.ClassDeclaration, {
340
- name: "MyClass",
341
- bases: ["BaseClass"],
363
+ const methodRefkey = refkey();
364
+ const classMethodRefkey = refkey();
365
+ const staticMethodRefkey = refkey();
366
+ const result = toSourceText([_$createComponent(py.StatementList, {
342
367
  get children() {
343
- return _$createComponent(py.StatementList, {
368
+ return [_$createComponent(py.ClassDeclaration, {
369
+ name: "MyClass",
370
+ bases: ["BaseClass"],
344
371
  get children() {
345
- return [_$createComponent(py.VariableDeclaration, {
346
- name: "a",
347
- type: "int"
348
- }), _$createComponent(py.VariableDeclaration, {
349
- name: "b",
350
- type: "int"
351
- }), _$createComponent(py.FunctionDeclaration, {
352
- name: "my_method",
353
- parameters: [{
354
- name: "a",
355
- type: "int"
356
- }, {
357
- name: "b",
358
- type: "int"
359
- }],
360
- returnType: "int",
361
- instanceFunction: true,
362
- children: "return a + b"
363
- }), _$createComponent(py.FunctionDeclaration, {
364
- name: "my_class_method",
365
- instanceFunction: false,
366
- classFunction: true,
367
- returnType: "int",
368
- children: "pass"
369
- }), _$createComponent(py.FunctionDeclaration, {
370
- name: "my_standalone_function",
371
- instanceFunction: false,
372
- returnType: "int",
373
- children: "pass"
374
- })];
372
+ return _$createComponent(py.StatementList, {
373
+ get children() {
374
+ return [_$createComponent(py.VariableDeclaration, {
375
+ name: "a",
376
+ type: "int",
377
+ instanceVariable: true
378
+ }), _$createComponent(py.VariableDeclaration, {
379
+ name: "b",
380
+ type: "int",
381
+ instanceVariable: true
382
+ }), _$createComponent(py.FunctionDeclaration, {
383
+ name: "my_method",
384
+ parameters: [{
385
+ name: "a",
386
+ type: "int"
387
+ }, {
388
+ name: "b",
389
+ type: "int"
390
+ }],
391
+ returnType: "int",
392
+ instanceFunction: true,
393
+ refkey: methodRefkey,
394
+ children: "return a + b"
395
+ }), _$createComponent(py.FunctionDeclaration, {
396
+ name: "my_class_method",
397
+ classFunction: true,
398
+ returnType: "int",
399
+ refkey: classMethodRefkey,
400
+ children: "pass"
401
+ }), _$createComponent(py.FunctionDeclaration, {
402
+ name: "my_standalone_function",
403
+ returnType: "int",
404
+ refkey: staticMethodRefkey,
405
+ children: "pass"
406
+ })];
407
+ }
408
+ });
375
409
  }
376
- });
410
+ }), classMethodRefkey, staticMethodRefkey];
377
411
  }
378
- })]]);
412
+ })]);
379
413
  const expected = d`
380
414
  class MyClass(BaseClass):
381
415
  a: int = None
@@ -389,8 +423,9 @@ describe("Python Class - FunctionDeclaration", () => {
389
423
  def my_standalone_function() -> int:
390
424
  pass
391
425
 
392
-
393
-
426
+
427
+ MyClass.my_class_method
428
+ MyClass.my_standalone_function
394
429
  `;
395
430
  expect(result).toRenderTo(expected);
396
431
  });
@@ -68,9 +68,15 @@ describe("Python Enum", () => {
68
68
  const result = toSourceText([_$createComponent(py.StatementList, {
69
69
  get children() {
70
70
  return [_$createComponent(py.ClassDeclaration, {
71
- name: "Dog"
71
+ name: "Dog",
72
+ get refkey() {
73
+ return refkey("Dog");
74
+ }
72
75
  }), _$createComponent(py.ClassDeclaration, {
73
- name: "Cat"
76
+ name: "Cat",
77
+ get refkey() {
78
+ return refkey("Cat");
79
+ }
74
80
  }), _$createComponent(py.EnumDeclaration, {
75
81
  name: "Animal",
76
82
  baseType: "Enum",
@@ -46,7 +46,6 @@ it("uses import from external library in multiple functions", () => {
46
46
  get returnType() {
47
47
  return py.requestsModule["models"]["Response"];
48
48
  },
49
- instanceFunction: true,
50
49
  get children() {
51
50
  return _$createComponent(py.StatementList, {
52
51
  get children() {
@@ -75,7 +74,6 @@ it("uses import from external library in multiple functions", () => {
75
74
  get returnType() {
76
75
  return py.requestsModule["models"]["Response"];
77
76
  },
78
- instanceFunction: true,
79
77
  get children() {
80
78
  return _$createComponent(py.StatementList, {
81
79
  get children() {
@@ -104,12 +102,12 @@ it("uses import from external library in multiple functions", () => {
104
102
  from requests import post
105
103
  from requests.models import Response
106
104
 
107
- def get_user(self, user_id: int) -> Response:
105
+ def get_user(user_id: int) -> Response:
108
106
  response = get(1)
109
107
  return response.json()
110
108
 
111
109
 
112
- def create_user(self, user_name: string) -> Response:
110
+ def create_user(user_name: string) -> Response:
113
111
  response = post(1)
114
112
  return response.json()
115
113
 
@@ -126,7 +124,10 @@ it("uses import from external library in multiple class methods", () => {
126
124
  return [_$createComponent(py.VariableDeclaration, {
127
125
  name: "some_var",
128
126
  initializer: 12,
129
- instanceVariable: true
127
+ instanceVariable: true,
128
+ get refkey() {
129
+ return refkey("some_var");
130
+ }
130
131
  }), _$createComponent(py.FunctionDeclaration, {
131
132
  name: "getUser",
132
133
  parameters: [{
@@ -7,11 +7,10 @@ import { assertFileContents, toSourceText, toSourceTextMultiple } from "./utils.
7
7
  describe("Function Declaration", () => {
8
8
  it("renders a function with no body as 'pass'", () => {
9
9
  const result = toSourceText([_$createComponent(py.FunctionDeclaration, {
10
- name: "foo",
11
- instanceFunction: true
10
+ name: "foo"
12
11
  })]);
13
12
  expect(result).toRenderTo(d`
14
- def foo(self):
13
+ def foo():
15
14
  pass
16
15
 
17
16
 
@@ -35,12 +34,10 @@ describe("Function Declaration", () => {
35
34
  get children() {
36
35
  return [_$createComponent(py.FunctionDeclaration, {
37
36
  name: "foo",
38
- instanceFunction: true,
39
37
  returnType: "int",
40
38
  refkey: refkeyFoo
41
39
  }), _$createComponent(py.FunctionDeclaration, {
42
40
  name: "bar",
43
- instanceFunction: true,
44
41
  returnType: "int",
45
42
  get children() {
46
43
  return _$createComponent(py.VariableDeclaration, {
@@ -58,26 +55,33 @@ describe("Function Declaration", () => {
58
55
  }
59
56
  })]);
60
57
  expect(result).toRenderTo(d`
61
- def foo(self) -> int:
58
+ def foo() -> int:
62
59
  pass
63
60
 
64
- def bar(self) -> int:
61
+ def bar() -> int:
65
62
  result: int = foo()
66
63
 
67
64
 
68
65
  `);
69
66
  });
70
67
  it("renders an instance function with a body", () => {
71
- const result = toSourceText([_$createComponent(py.FunctionDeclaration, {
72
- name: "bar",
73
- instanceFunction: true,
74
- children: "print('hi')"
68
+ const result = toSourceText([_$createComponent(py.ClassDeclaration, {
69
+ name: "MyClass",
70
+ get children() {
71
+ return _$createComponent(py.FunctionDeclaration, {
72
+ name: "bar",
73
+ instanceFunction: true,
74
+ children: "print('hi')"
75
+ });
76
+ }
75
77
  })]);
76
78
  expect(result).toRenderTo(d`
77
- def bar(self):
78
- print('hi')
79
+ class MyClass:
80
+ def bar(self):
81
+ print('hi')
79
82
 
80
83
 
84
+
81
85
  `);
82
86
  });
83
87
  it("renders a function with parameters", () => {
@@ -106,16 +110,23 @@ describe("Function Declaration", () => {
106
110
  `);
107
111
  });
108
112
  it("renders an __init__ function with no body as 'pass'", () => {
109
- const result = toSourceText([_$createComponent(py.InitFunctionDeclaration, {
110
- parameters: [{
111
- name: "x"
112
- }]
113
+ const result = toSourceText([_$createComponent(py.ClassDeclaration, {
114
+ name: "MyClass",
115
+ get children() {
116
+ return _$createComponent(py.InitFunctionDeclaration, {
117
+ parameters: [{
118
+ name: "x"
119
+ }]
120
+ });
121
+ }
113
122
  })]);
114
123
  expect(result).toRenderTo(d`
115
- def __init__(self, x):
116
- pass
124
+ class MyClass:
125
+ def __init__(self, x):
126
+ pass
117
127
 
118
-
128
+
129
+
119
130
  `);
120
131
  });
121
132
  it("can be an async function", () => {
@@ -143,7 +154,10 @@ describe("Function Declaration", () => {
143
154
  expect(toSourceText([_$createComponent(py.StatementList, {
144
155
  get children() {
145
156
  return [_$createComponent(py.ClassDeclaration, {
146
- name: "Foo"
157
+ name: "Foo",
158
+ get refkey() {
159
+ return refkey("Foo");
160
+ }
147
161
  }), _$createComponent(py.FunctionDeclaration, {
148
162
  async: true,
149
163
  name: "foo",
@@ -195,15 +209,22 @@ describe("Function Declaration", () => {
195
209
  name: "x",
196
210
  type: "int"
197
211
  }];
198
- const decl = _$createComponent(py.FunctionDeclaration, {
199
- name: "foo",
200
- instanceFunction: true,
201
- parameters: parameters,
202
- children: "self.attribute = \"value\""
212
+ const decl = _$createComponent(py.ClassDeclaration, {
213
+ name: "MyClass",
214
+ get children() {
215
+ return _$createComponent(py.FunctionDeclaration, {
216
+ name: "foo",
217
+ instanceFunction: true,
218
+ parameters: parameters,
219
+ children: "self.attribute = \"value\""
220
+ });
221
+ }
203
222
  });
204
223
  expect(toSourceText([decl])).toBe(d`
205
- def foo(self, x: int):
206
- self.attribute = "value"
224
+ class MyClass:
225
+ def foo(self, x: int):
226
+ self.attribute = "value"
227
+
207
228
 
208
229
  `);
209
230
  });
@@ -212,13 +233,20 @@ describe("Function Declaration", () => {
212
233
  name: "x",
213
234
  type: "int"
214
235
  }];
215
- const decl = _$createComponent(py.InitFunctionDeclaration, {
216
- parameters: parameters,
217
- children: "self.attribute = \"value\""
236
+ const decl = _$createComponent(py.ClassDeclaration, {
237
+ name: "MyClass",
238
+ get children() {
239
+ return _$createComponent(py.InitFunctionDeclaration, {
240
+ parameters: parameters,
241
+ children: "self.attribute = \"value\""
242
+ });
243
+ }
218
244
  });
219
245
  expect(toSourceText([decl])).toBe(d`
220
- def __init__(self, x: int):
221
- self.attribute = "value"
246
+ class MyClass:
247
+ def __init__(self, x: int):
248
+ self.attribute = "value"
249
+
222
250
 
223
251
  `);
224
252
  });
@@ -287,16 +315,25 @@ describe("Function Declaration", () => {
287
315
  path: "mod1.py",
288
316
  get children() {
289
317
  return _$createComponent(py.ClassDeclaration, {
290
- name: "Foo"
318
+ name: "Foo",
319
+ get refkey() {
320
+ return refkey("Foo");
321
+ }
291
322
  });
292
323
  }
293
324
  }), _$createComponent(py.SourceFile, {
294
325
  path: "mod2.py",
295
326
  get children() {
296
327
  return [_$createComponent(py.ClassDeclaration, {
297
- name: "A"
328
+ name: "A",
329
+ get refkey() {
330
+ return refkey("A");
331
+ }
298
332
  }), _$createComponent(py.ClassDeclaration, {
299
- name: "B"
333
+ name: "B",
334
+ get refkey() {
335
+ return refkey("B");
336
+ }
300
337
  })];
301
338
  }
302
339
  }), _$createComponent(py.SourceFile, {
@@ -15,14 +15,8 @@ describe("ImportStatement", () => {
15
15
  expect(result).toRenderTo(expected);
16
16
  });
17
17
  it("renders named imports", () => {
18
- const sqrtSymbol = createPythonSymbol("sqrt", {
19
- binder: undefined,
20
- scope: undefined
21
- });
22
- const piSymbol = createPythonSymbol("pi", {
23
- binder: undefined,
24
- scope: undefined
25
- });
18
+ const sqrtSymbol = createPythonSymbol("sqrt", undefined);
19
+ const piSymbol = createPythonSymbol("pi", undefined);
26
20
  const symbols = new Set([new ImportedSymbol(sqrtSymbol, sqrtSymbol), new ImportedSymbol(piSymbol, piSymbol)]);
27
21
  const result = toSourceText([_$createComponent(ImportStatement, {
28
22
  path: "math",
@@ -35,21 +29,12 @@ describe("ImportStatement", () => {
35
29
  describe("ImportStatements", () => {
36
30
  it("renders multiple import statements", () => {
37
31
  const pythonModuleScope = createPythonModuleScope("math", undefined);
38
- const sqrtSymbol = createPythonSymbol("sqrt", {
39
- binder: undefined,
40
- scope: undefined
41
- });
42
- const piSymbol = createPythonSymbol("pi", {
43
- binder: undefined,
44
- scope: undefined
45
- });
32
+ const sqrtSymbol = createPythonSymbol("sqrt", undefined);
33
+ const piSymbol = createPythonSymbol("pi", undefined);
46
34
  const mathSymbols = new Set([new ImportedSymbol(sqrtSymbol, sqrtSymbol), new ImportedSymbol(piSymbol, piSymbol)]);
47
35
  const sysModuleScope = createPythonModuleScope("sys", undefined);
48
36
  const requestsScope = createPythonModuleScope("requests", undefined);
49
- const getSymbol = createPythonSymbol("get", {
50
- binder: undefined,
51
- scope: undefined
52
- });
37
+ const getSymbol = createPythonSymbol("get", undefined);
53
38
  const requestsSymbols = new Set([new ImportedSymbol(getSymbol, getSymbol)]);
54
39
  const records = new ImportRecords([[pythonModuleScope, {
55
40
  symbols: mathSymbols
@@ -70,24 +55,12 @@ describe("ImportStatements", () => {
70
55
  });
71
56
  it("renders multiple import statements, but joining imports from the same module", () => {
72
57
  const pythonModuleScope = createPythonModuleScope("math", undefined);
73
- const sqrtSymbol = createPythonSymbol("sqrt", {
74
- binder: undefined,
75
- scope: undefined
76
- });
77
- const piSymbol = createPythonSymbol("pi", {
78
- binder: undefined,
79
- scope: undefined
80
- });
58
+ const sqrtSymbol = createPythonSymbol("sqrt", undefined);
59
+ const piSymbol = createPythonSymbol("pi", undefined);
81
60
  const mathSymbols = new Set([new ImportedSymbol(sqrtSymbol, sqrtSymbol), new ImportedSymbol(piSymbol, piSymbol)]);
82
61
  const requestsScope = createPythonModuleScope("requests", undefined);
83
- const getSymbol = createPythonSymbol("get", {
84
- binder: undefined,
85
- scope: undefined
86
- });
87
- const postSymbol = createPythonSymbol("post", {
88
- binder: undefined,
89
- scope: undefined
90
- });
62
+ const getSymbol = createPythonSymbol("get", undefined);
63
+ const postSymbol = createPythonSymbol("post", undefined);
91
64
  const requestsSymbols = new Set([new ImportedSymbol(getSymbol, getSymbol), new ImportedSymbol(postSymbol, postSymbol)]);
92
65
  const records = new ImportRecords([[pythonModuleScope, {
93
66
  symbols: mathSymbols
@@ -1,5 +1,4 @@
1
- import { Binder, Children, ContentOutputFile, NamePolicy, OutputDirectory, PrintTreeOptions, SymbolCreator } from "@alloy-js/core";
2
- import { CustomOutputScope } from "../src/symbols/custom-output-scope.js";
1
+ import { Binder, Children, ContentOutputFile, NamePolicy, OutputDirectory, OutputScope, PrintTreeOptions, SymbolCreator } from "@alloy-js/core";
3
2
  import { PythonModuleScope } from "../src/symbols/index.js";
4
3
  export declare function findFile(res: OutputDirectory, path: string): ContentOutputFile;
5
4
  export declare function assertFileContents(res: OutputDirectory, expectedFiles: Record<string, string>): void;
@@ -19,5 +18,5 @@ export declare function toSourceText(c: Children[], { policy, externals, options
19
18
  };
20
19
  printOptions?: PrintTreeOptions;
21
20
  }): string;
22
- export declare function createPythonModuleScope(name: string, parent: CustomOutputScope | undefined, binder?: Binder | undefined): PythonModuleScope;
21
+ export declare function createPythonModuleScope(name: string, parent: OutputScope | undefined, binder?: Binder | undefined): PythonModuleScope;
23
22
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts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CAAC;CAC5B,GACL,MAAM,CAUR;AAGD,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,MAAM,GAAE,MAAM,GAAG,SAAqB,GACrC,iBAAiB,CAInB"}
@@ -3,6 +3,7 @@ import { Output, render } from "@alloy-js/core";
3
3
  import { dedent } from "@alloy-js/core/testing";
4
4
  import { expect } from "vitest";
5
5
  import * as py from "../src/components/index.js";
6
+ import { pythonNameConflictResolver } from "../src/name-conflict-resolver.js";
6
7
  import { createPythonNamePolicy } from "../src/name-policy.js";
7
8
  import { PythonModuleScope } from "../src/symbols/index.js";
8
9
  export function findFile(res, path) {
@@ -55,6 +56,7 @@ export function toSourceTextMultiple(sourceFiles, {
55
56
  const content = _$createComponent(Output, {
56
57
  externals: mergedExternals,
57
58
  namePolicy: policy,
59
+ nameConflictResolver: pythonNameConflictResolver,
58
60
  children: sourceFiles
59
61
  });
60
62
  return render(content, printOptions);
@@ -81,8 +83,7 @@ export function toSourceText(c, {
81
83
 
82
84
  // Helper function to create a PythonModuleScope to be used in tests
83
85
  export function createPythonModuleScope(name, parent, binder = undefined) {
84
- return new PythonModuleScope(name, {
85
- parent: parent,
86
+ return new PythonModuleScope(name, parent, {
86
87
  binder: binder
87
88
  });
88
89
  }