@alloy-js/python 0.3.0-dev.4 → 0.3.0-dev.6

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 (61) hide show
  1. package/dist/src/components/CallSignature.d.ts +6 -4
  2. package/dist/src/components/CallSignature.d.ts.map +1 -1
  3. package/dist/src/components/CallSignature.js +23 -26
  4. package/dist/src/components/CallSignature.js.map +1 -1
  5. package/dist/src/components/FutureStatement.d.ts +35 -0
  6. package/dist/src/components/FutureStatement.d.ts.map +1 -0
  7. package/dist/src/components/FutureStatement.js +31 -0
  8. package/dist/src/components/FutureStatement.js.map +1 -0
  9. package/dist/src/components/SourceFile.d.ts +8 -2
  10. package/dist/src/components/SourceFile.d.ts.map +1 -1
  11. package/dist/src/components/SourceFile.js +124 -8
  12. package/dist/src/components/SourceFile.js.map +1 -1
  13. package/dist/src/components/index.d.ts +1 -0
  14. package/dist/src/components/index.d.ts.map +1 -1
  15. package/dist/src/components/index.js +1 -0
  16. package/dist/src/components/index.js.map +1 -1
  17. package/dist/test/callsignatures.test.js +127 -0
  18. package/dist/test/callsignatures.test.js.map +1 -1
  19. package/dist/test/classdeclarations.test.js +2 -0
  20. package/dist/test/classdeclarations.test.js.map +1 -1
  21. package/dist/test/dataclassdeclarations.test.js +13 -0
  22. package/dist/test/dataclassdeclarations.test.js.map +1 -1
  23. package/dist/test/enums.test.js +7 -0
  24. package/dist/test/enums.test.js.map +1 -1
  25. package/dist/test/externals.test.js +2 -0
  26. package/dist/test/externals.test.js.map +1 -1
  27. package/dist/test/functiondeclaration.test.js +2 -0
  28. package/dist/test/functiondeclaration.test.js.map +1 -1
  29. package/dist/test/methoddeclaration.test.js +1 -0
  30. package/dist/test/methoddeclaration.test.js.map +1 -1
  31. package/dist/test/namepolicies.test.js +1 -0
  32. package/dist/test/namepolicies.test.js.map +1 -1
  33. package/dist/test/propertydeclaration.test.js +1 -0
  34. package/dist/test/propertydeclaration.test.js.map +1 -1
  35. package/dist/test/pydocs.test.js +1 -1
  36. package/dist/test/pydocs.test.js.map +1 -1
  37. package/dist/test/sourcefiles.test.js +921 -39
  38. package/dist/test/sourcefiles.test.js.map +1 -1
  39. package/dist/test/utils.d.ts +2 -2
  40. package/dist/test/utils.d.ts.map +1 -1
  41. package/dist/test/utils.js +9 -9
  42. package/dist/test/utils.js.map +1 -1
  43. package/dist/tsconfig.tsbuildinfo +1 -1
  44. package/package.json +2 -2
  45. package/src/components/CallSignature.tsx +41 -36
  46. package/src/components/FutureStatement.tsx +38 -0
  47. package/src/components/SourceFile.tsx +128 -8
  48. package/src/components/index.ts +1 -0
  49. package/temp/api.json +169 -5
  50. package/test/callsignatures.test.tsx +110 -0
  51. package/test/classdeclarations.test.tsx +2 -0
  52. package/test/dataclassdeclarations.test.tsx +13 -0
  53. package/test/enums.test.tsx +7 -0
  54. package/test/externals.test.tsx +2 -0
  55. package/test/functiondeclaration.test.tsx +2 -0
  56. package/test/methoddeclaration.test.tsx +1 -0
  57. package/test/namepolicies.test.tsx +1 -0
  58. package/test/propertydeclaration.test.tsx +1 -0
  59. package/test/pydocs.test.tsx +1 -1
  60. package/test/sourcefiles.test.tsx +754 -48
  61. package/test/utils.tsx +10 -5
@@ -96,6 +96,35 @@ describe("Call Signature Parameters", () => {
96
96
  a: int = 5, b: str = "hello"
97
97
  `);
98
98
  });
99
+ it("renders keyword-only parameters with * marker", () => {
100
+ const result = toSourceText([
101
+ <py.CallSignatureParameters
102
+ parameters={[
103
+ { name: "a", type: "str" },
104
+ "*",
105
+ { name: "b", type: "int", default: 10 },
106
+ { name: "c", type: "bool", default: true },
107
+ ]}
108
+ />,
109
+ ]);
110
+ expect(result).toRenderTo(d`
111
+ a: str, *, b: int = 10, c: bool = True
112
+ `);
113
+ });
114
+ it("renders only keyword-only parameters with * marker at start", () => {
115
+ const result = toSourceText([
116
+ <py.CallSignatureParameters
117
+ parameters={[
118
+ "*",
119
+ { name: "a", type: "str", default: "hello" },
120
+ { name: "b", type: "int", default: 42 },
121
+ ]}
122
+ />,
123
+ ]);
124
+ expect(result).toRenderTo(d`
125
+ *, a: str = "hello", b: int = 42
126
+ `);
127
+ });
99
128
  });
100
129
 
101
130
  describe("Call Signature", () => {
@@ -281,4 +310,85 @@ describe("Call Signature - Parameter Descriptors", () => {
281
310
  [T, U](a: int, b: str = "default_value") -> int
282
311
  `);
283
312
  });
313
+ it("renders a call signature with keyword-only parameters using * marker", () => {
314
+ const result = toSourceText([
315
+ <py.CallSignature
316
+ parameters={[
317
+ { name: "id", type: "str" },
318
+ "*",
319
+ { name: "locale", type: "str", default: "en-US" },
320
+ { name: "debug", type: "bool", default: false },
321
+ ]}
322
+ returnType="str"
323
+ />,
324
+ ]);
325
+ expect(result).toRenderTo(d`
326
+ (id: str, *, locale: str = "en-US", debug: bool = False) -> str
327
+ `);
328
+ });
329
+ it("renders a call signature with only keyword-only parameters", () => {
330
+ const result = toSourceText([
331
+ <py.CallSignature
332
+ parameters={[
333
+ "*",
334
+ { name: "name", type: "str", default: "alice" },
335
+ { name: "age", type: "int", default: 30 },
336
+ ]}
337
+ returnType="None"
338
+ />,
339
+ ]);
340
+ expect(result).toRenderTo(d`
341
+ (*, name: str = "alice", age: int = 30) -> None
342
+ `);
343
+ });
344
+ it("renders a call signature with positional, keyword-only, and *args/**kwargs", () => {
345
+ const result = toSourceText([
346
+ <py.CallSignature
347
+ parameters={[
348
+ { name: "a", type: "int" },
349
+ "*",
350
+ { name: "b", type: "str", default: "hello" },
351
+ ]}
352
+ args
353
+ kwargs
354
+ returnType="None"
355
+ />,
356
+ ]);
357
+ expect(result).toRenderTo(d`
358
+ (a: int, *, b: str = "hello", *args, **kwargs) -> None
359
+ `);
360
+ });
361
+ it("renders a call signature with positional-only parameters using / marker", () => {
362
+ const result = toSourceText([
363
+ <py.CallSignature
364
+ parameters={[
365
+ { name: "a", type: "int" },
366
+ { name: "b", type: "str" },
367
+ "/",
368
+ { name: "c", type: "bool" },
369
+ ]}
370
+ returnType="None"
371
+ />,
372
+ ]);
373
+ expect(result).toRenderTo(d`
374
+ (a: int, b: str, /, c: bool) -> None
375
+ `);
376
+ });
377
+ it("renders a call signature with positional-only, regular, and keyword-only parameters", () => {
378
+ const result = toSourceText([
379
+ <py.CallSignature
380
+ parameters={[
381
+ { name: "a", type: "int" },
382
+ "/",
383
+ { name: "b", type: "str" },
384
+ "*",
385
+ { name: "c", type: "bool", default: true },
386
+ ]}
387
+ returnType="None"
388
+ />,
389
+ ]);
390
+ expect(result).toRenderTo(d`
391
+ (a: int, /, b: str, *, c: bool = True) -> None
392
+ `);
393
+ });
284
394
  });
@@ -108,6 +108,7 @@ describe("Python Class", () => {
108
108
  const mod2Expected = d`
109
109
  from mod1 import A
110
110
 
111
+
111
112
  class B(A):
112
113
  pass
113
114
 
@@ -116,6 +117,7 @@ describe("Python Class", () => {
116
117
  const mod3Expected = d`
117
118
  from folder.mod2 import B
118
119
 
120
+
119
121
  class C(B):
120
122
  pass
121
123
 
@@ -27,6 +27,7 @@ describe("DataclassDeclaration", () => {
27
27
  d`
28
28
  from dataclasses import dataclass
29
29
 
30
+
30
31
  @dataclass
31
32
  class User:
32
33
  """
@@ -74,6 +75,7 @@ describe("DataclassDeclaration", () => {
74
75
  from dataclasses import dataclass
75
76
  from dataclasses import KW_ONLY
76
77
 
78
+
77
79
  @dataclass
78
80
  class User:
79
81
  id: int
@@ -106,6 +108,7 @@ describe("DataclassDeclaration", () => {
106
108
  d`
107
109
  from dataclasses import dataclass
108
110
 
111
+
109
112
  @dataclass(frozen=True, slots=True, kw_only=True)
110
113
  class User:
111
114
  id: int
@@ -141,6 +144,7 @@ describe("DataclassDeclaration", () => {
141
144
  d`
142
145
  from dataclasses import dataclass
143
146
 
147
+
144
148
  @dataclass(init=True, repr=False, eq=True, order=False, unsafe_hash=True, frozen=True, match_args=False, kw_only=True, slots=True, weakref_slot=False)
145
149
  class User:
146
150
  pass
@@ -178,6 +182,7 @@ describe("DataclassDeclaration", () => {
178
182
  d`
179
183
  from dataclasses import dataclass
180
184
 
185
+
181
186
  @dataclass(slots=True, weakref_slot=True)
182
187
  class User:
183
188
  pass
@@ -213,6 +218,7 @@ describe("DataclassDeclaration", () => {
213
218
  d`
214
219
  from dataclasses import dataclass
215
220
 
221
+
216
222
  @dataclass(order=True)
217
223
  class User:
218
224
  pass
@@ -398,6 +404,7 @@ describe("DataclassDeclaration", () => {
398
404
  d`
399
405
  from dataclasses import dataclass
400
406
 
407
+
401
408
  @dataclass(kw_only=True)
402
409
  class User:
403
410
  id: int
@@ -421,6 +428,7 @@ describe("DataclassDeclaration", () => {
421
428
  d`
422
429
  from dataclasses import dataclass
423
430
 
431
+
424
432
  @dataclass
425
433
  class User(Base):
426
434
  pass
@@ -503,6 +511,7 @@ describe("DataclassDeclaration", () => {
503
511
  d`
504
512
  from dataclasses import dataclass
505
513
 
514
+
506
515
  @dataclass(unsafe_hash=True)
507
516
  class User:
508
517
  pass
@@ -556,6 +565,7 @@ describe("DataclassDeclaration", () => {
556
565
  d`
557
566
  from dataclasses import dataclass
558
567
 
568
+
559
569
  @dataclass(frozen=True)
560
570
  class User:
561
571
  pass
@@ -578,6 +588,7 @@ describe("DataclassDeclaration", () => {
578
588
  d`
579
589
  from dataclasses import dataclass
580
590
 
591
+
581
592
  @dataclass(slots=True)
582
593
  class User:
583
594
  pass
@@ -627,6 +638,7 @@ describe("DataclassDeclaration", () => {
627
638
  "models.py": `
628
639
  from dataclasses import dataclass
629
640
 
641
+
630
642
  @dataclass
631
643
  class User:
632
644
  id: int
@@ -636,6 +648,7 @@ describe("DataclassDeclaration", () => {
636
648
  "services.py": `
637
649
  from models import User
638
650
 
651
+
639
652
  def get_user() -> User:
640
653
  user: User = User(1, "Alice")
641
654
  return user
@@ -24,6 +24,7 @@ describe("Python Enum", () => {
24
24
  const expected = d`
25
25
  from enum import IntEnum
26
26
 
27
+
27
28
  class Color(IntEnum):
28
29
  RED = 1
29
30
  GREEN = 2
@@ -52,6 +53,7 @@ describe("Python Enum", () => {
52
53
  const expected = d`
53
54
  from enum import IntEnum
54
55
 
56
+
55
57
  class Color(IntEnum):
56
58
  RED = "1"
57
59
  GREEN = 2
@@ -83,6 +85,7 @@ describe("Python Enum", () => {
83
85
  const expected = d`
84
86
  from enum import Enum
85
87
 
88
+
86
89
  class Dog:
87
90
  pass
88
91
 
@@ -113,6 +116,7 @@ describe("Python Enum", () => {
113
116
  from enum import auto
114
117
  from enum import Enum
115
118
 
119
+
116
120
  class Animal(Enum):
117
121
  DOG = auto()
118
122
  CAT = auto()
@@ -144,6 +148,7 @@ describe("Python Enum", () => {
144
148
  from enum import auto
145
149
  from enum import Flag
146
150
 
151
+
147
152
  class Permission(Flag):
148
153
  READ = 1
149
154
  WRITE = auto()
@@ -172,6 +177,7 @@ describe("Python Enum", () => {
172
177
  const expected = d`
173
178
  from enum import Enum
174
179
 
180
+
175
181
  Direction = Enum('Direction', ['NORTH', 'SOUTH', 'EAST', 'WEST'])
176
182
  `;
177
183
  expect(result).toRenderTo(expected);
@@ -194,6 +200,7 @@ describe("Python Enum", () => {
194
200
  const expected = d`
195
201
  from enum import Enum
196
202
 
203
+
197
204
  Priority = Enum('Priority', {'HIGH' : 1, 'MEDIUM' : 2, 'LOW' : 3})
198
205
  `;
199
206
  expect(result).toRenderTo(expected);
@@ -94,6 +94,7 @@ it("uses import from external library in multiple functions", () => {
94
94
  from requests import post
95
95
  from requests.models import Response
96
96
 
97
+
97
98
  def get_user(user_id: int) -> Response:
98
99
  response = get(1)
99
100
  return response.json()
@@ -170,6 +171,7 @@ it("uses import from external library in multiple class methods", () => {
170
171
  from requests import post
171
172
  from requests.models import Response
172
173
 
174
+
173
175
  class UserClient:
174
176
  some_var = 12
175
177
  def get_user(self, user_id: int) -> Response:
@@ -289,6 +289,7 @@ describe("Function Declaration", () => {
289
289
  expect(toSourceText([decl], { externals: [abcModule] })).toBe(d`
290
290
  from abc import abstractmethod
291
291
 
292
+
292
293
  class MyClass:
293
294
  @abstractmethod
294
295
  def methoddef(self, x: int):
@@ -453,6 +454,7 @@ describe("Function Declaration", () => {
453
454
  from mod2 import A
454
455
  from mod2 import B
455
456
 
457
+
456
458
  async def foo(x: A, y: B, *args, **kwargs) -> Foo:
457
459
  pass
458
460
 
@@ -181,6 +181,7 @@ describe("Method-like Declarations", () => {
181
181
  expect(toSourceText([decl], { externals: [abcModule] })).toBe(d`
182
182
  from abc import abstractmethod
183
183
 
184
+
184
185
  class MyClass:
185
186
  @abstractmethod
186
187
  def methoddef(self, x: int):
@@ -34,6 +34,7 @@ it("correct formatting of Enum name and EnumMember names", () => {
34
34
  const expected = d`
35
35
  from enum import Enum
36
36
 
37
+
37
38
  Priority = Enum('Priority', {'HIGH' : 1, 'MEDIUM' : 2, 'LOW_VALUE' : 3})
38
39
  `;
39
40
  expect(result).toRenderTo(expected);
@@ -170,6 +170,7 @@ describe("PropertyDeclaration", () => {
170
170
  expect(toSourceText([decl], { externals: [abcModule] })).toBe(d`
171
171
  from abc import abstractmethod
172
172
 
173
+
173
174
  class MyClass:
174
175
  @property
175
176
  @abstractmethod
@@ -1138,6 +1138,7 @@ describe("Full example", () => {
1138
1138
  const expected = d`
1139
1139
  from enum import IntEnum
1140
1140
 
1141
+
1141
1142
  class Color(IntEnum):
1142
1143
  """
1143
1144
  An enum representing colors.
@@ -1219,7 +1220,6 @@ describe("Full example", () => {
1219
1220
  * Improve error messages
1220
1221
  """
1221
1222
 
1222
-
1223
1223
  default_timeout = 30
1224
1224
 
1225
1225
  max_retries = 3