@alloy-js/python 0.0.1

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 (206) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/LICENSE +7 -0
  3. package/api-extractor.json +4 -0
  4. package/dist/src/builtins/python.d.ts +9 -0
  5. package/dist/src/builtins/python.d.ts.map +1 -0
  6. package/dist/src/builtins/python.js +17 -0
  7. package/dist/src/components/Atom.d.ts +19 -0
  8. package/dist/src/components/Atom.d.ts.map +1 -0
  9. package/dist/src/components/Atom.js +82 -0
  10. package/dist/src/components/CallSignature.d.ts +79 -0
  11. package/dist/src/components/CallSignature.d.ts.map +1 -0
  12. package/dist/src/components/CallSignature.js +201 -0
  13. package/dist/src/components/ClassDeclaration.d.ts +37 -0
  14. package/dist/src/components/ClassDeclaration.d.ts.map +1 -0
  15. package/dist/src/components/ClassDeclaration.js +83 -0
  16. package/dist/src/components/ClassInstantiation.d.ts +24 -0
  17. package/dist/src/components/ClassInstantiation.d.ts.map +1 -0
  18. package/dist/src/components/ClassInstantiation.js +35 -0
  19. package/dist/src/components/Declaration.d.ts +48 -0
  20. package/dist/src/components/Declaration.d.ts.map +1 -0
  21. package/dist/src/components/Declaration.js +37 -0
  22. package/dist/src/components/EnumDeclaration.d.ts +164 -0
  23. package/dist/src/components/EnumDeclaration.d.ts.map +1 -0
  24. package/dist/src/components/EnumDeclaration.js +278 -0
  25. package/dist/src/components/EnumMember.d.ts +46 -0
  26. package/dist/src/components/EnumMember.d.ts.map +1 -0
  27. package/dist/src/components/EnumMember.js +67 -0
  28. package/dist/src/components/FunctionCallExpression.d.ts +19 -0
  29. package/dist/src/components/FunctionCallExpression.d.ts.map +1 -0
  30. package/dist/src/components/FunctionCallExpression.js +40 -0
  31. package/dist/src/components/FunctionDeclaration.d.ts +47 -0
  32. package/dist/src/components/FunctionDeclaration.d.ts.map +1 -0
  33. package/dist/src/components/FunctionDeclaration.js +107 -0
  34. package/dist/src/components/ImportStatement.d.ts +39 -0
  35. package/dist/src/components/ImportStatement.d.ts.map +1 -0
  36. package/dist/src/components/ImportStatement.js +104 -0
  37. package/dist/src/components/MemberExpression.d.ts +97 -0
  38. package/dist/src/components/MemberExpression.d.ts.map +1 -0
  39. package/dist/src/components/MemberExpression.js +308 -0
  40. package/dist/src/components/NoNamePolicy.d.ts +23 -0
  41. package/dist/src/components/NoNamePolicy.d.ts.map +1 -0
  42. package/dist/src/components/NoNamePolicy.js +27 -0
  43. package/dist/src/components/PyDoc.d.ts +90 -0
  44. package/dist/src/components/PyDoc.d.ts.map +1 -0
  45. package/dist/src/components/PyDoc.js +280 -0
  46. package/dist/src/components/PythonBlock.d.ts +23 -0
  47. package/dist/src/components/PythonBlock.d.ts.map +1 -0
  48. package/dist/src/components/PythonBlock.js +31 -0
  49. package/dist/src/components/Reference.d.ts +13 -0
  50. package/dist/src/components/Reference.d.ts.map +1 -0
  51. package/dist/src/components/Reference.js +18 -0
  52. package/dist/src/components/SourceFile.d.ts +46 -0
  53. package/dist/src/components/SourceFile.d.ts.map +1 -0
  54. package/dist/src/components/SourceFile.js +75 -0
  55. package/dist/src/components/StatementList.d.ts +25 -0
  56. package/dist/src/components/StatementList.d.ts.map +1 -0
  57. package/dist/src/components/StatementList.js +29 -0
  58. package/dist/src/components/VariableDeclaration.d.ts +62 -0
  59. package/dist/src/components/VariableDeclaration.d.ts.map +1 -0
  60. package/dist/src/components/VariableDeclaration.js +131 -0
  61. package/dist/src/components/index.d.ts +19 -0
  62. package/dist/src/components/index.d.ts.map +1 -0
  63. package/dist/src/components/index.js +18 -0
  64. package/dist/src/create-module.d.ts +16 -0
  65. package/dist/src/create-module.d.ts.map +1 -0
  66. package/dist/src/create-module.js +64 -0
  67. package/dist/src/index.d.ts +8 -0
  68. package/dist/src/index.d.ts.map +1 -0
  69. package/dist/src/index.js +7 -0
  70. package/dist/src/name-policy.d.ts +5 -0
  71. package/dist/src/name-policy.d.ts.map +1 -0
  72. package/dist/src/name-policy.js +47 -0
  73. package/dist/src/parameter-descriptor.d.ts +31 -0
  74. package/dist/src/parameter-descriptor.d.ts.map +1 -0
  75. package/dist/src/parameter-descriptor.js +1 -0
  76. package/dist/src/symbol-creation.d.ts +4 -0
  77. package/dist/src/symbol-creation.d.ts.map +1 -0
  78. package/dist/src/symbol-creation.js +24 -0
  79. package/dist/src/symbols/custom-output-scope.d.ts +10 -0
  80. package/dist/src/symbols/custom-output-scope.d.ts.map +1 -0
  81. package/dist/src/symbols/custom-output-scope.js +25 -0
  82. package/dist/src/symbols/index.d.ts +7 -0
  83. package/dist/src/symbols/index.d.ts.map +1 -0
  84. package/dist/src/symbols/index.js +6 -0
  85. package/dist/src/symbols/python-member-scope.d.ts +7 -0
  86. package/dist/src/symbols/python-member-scope.d.ts.map +1 -0
  87. package/dist/src/symbols/python-member-scope.js +9 -0
  88. package/dist/src/symbols/python-module-scope.d.ts +25 -0
  89. package/dist/src/symbols/python-module-scope.d.ts.map +1 -0
  90. package/dist/src/symbols/python-module-scope.js +52 -0
  91. package/dist/src/symbols/python-output-symbol.d.ts +19 -0
  92. package/dist/src/symbols/python-output-symbol.d.ts.map +1 -0
  93. package/dist/src/symbols/python-output-symbol.js +22 -0
  94. package/dist/src/symbols/reference.d.ts +4 -0
  95. package/dist/src/symbols/reference.d.ts.map +1 -0
  96. package/dist/src/symbols/reference.js +60 -0
  97. package/dist/src/symbols/scopes.d.ts +5 -0
  98. package/dist/src/symbols/scopes.d.ts.map +1 -0
  99. package/dist/src/symbols/scopes.js +4 -0
  100. package/dist/src/utils.d.ts +7 -0
  101. package/dist/src/utils.d.ts.map +1 -0
  102. package/dist/src/utils.js +12 -0
  103. package/dist/test/callsignatures.test.d.ts +2 -0
  104. package/dist/test/callsignatures.test.d.ts.map +1 -0
  105. package/dist/test/callsignatures.test.js +276 -0
  106. package/dist/test/classdeclarations.test.d.ts +2 -0
  107. package/dist/test/classdeclarations.test.d.ts.map +1 -0
  108. package/dist/test/classdeclarations.test.js +397 -0
  109. package/dist/test/classinstantiations.test.d.ts +2 -0
  110. package/dist/test/classinstantiations.test.d.ts.map +1 -0
  111. package/dist/test/classinstantiations.test.js +168 -0
  112. package/dist/test/enums.test.d.ts +2 -0
  113. package/dist/test/enums.test.d.ts.map +1 -0
  114. package/dist/test/enums.test.js +211 -0
  115. package/dist/test/externals.test.d.ts +2 -0
  116. package/dist/test/externals.test.d.ts.map +1 -0
  117. package/dist/test/externals.test.js +219 -0
  118. package/dist/test/functioncallexpressions.test.d.ts +2 -0
  119. package/dist/test/functioncallexpressions.test.d.ts.map +1 -0
  120. package/dist/test/functioncallexpressions.test.js +156 -0
  121. package/dist/test/functiondeclaration.test.d.ts +2 -0
  122. package/dist/test/functiondeclaration.test.d.ts.map +1 -0
  123. package/dist/test/functiondeclaration.test.js +363 -0
  124. package/dist/test/imports.test.d.ts +2 -0
  125. package/dist/test/imports.test.d.ts.map +1 -0
  126. package/dist/test/imports.test.js +262 -0
  127. package/dist/test/memberexpressions.test.d.ts +2 -0
  128. package/dist/test/memberexpressions.test.d.ts.map +1 -0
  129. package/dist/test/memberexpressions.test.js +879 -0
  130. package/dist/test/namepolicies.test.d.ts +2 -0
  131. package/dist/test/namepolicies.test.d.ts.map +1 -0
  132. package/dist/test/namepolicies.test.js +109 -0
  133. package/dist/test/pydocs.test.d.ts +2 -0
  134. package/dist/test/pydocs.test.d.ts.map +1 -0
  135. package/dist/test/pydocs.test.js +500 -0
  136. package/dist/test/references.test.d.ts +2 -0
  137. package/dist/test/references.test.d.ts.map +1 -0
  138. package/dist/test/references.test.js +49 -0
  139. package/dist/test/sourcefiles.test.d.ts +2 -0
  140. package/dist/test/sourcefiles.test.d.ts.map +1 -0
  141. package/dist/test/sourcefiles.test.js +198 -0
  142. package/dist/test/utils.d.ts +23 -0
  143. package/dist/test/utils.d.ts.map +1 -0
  144. package/dist/test/utils.js +88 -0
  145. package/dist/test/values.test.d.ts +2 -0
  146. package/dist/test/values.test.d.ts.map +1 -0
  147. package/dist/test/values.test.js +78 -0
  148. package/dist/test/variables.test.d.ts +2 -0
  149. package/dist/test/variables.test.d.ts.map +1 -0
  150. package/dist/test/variables.test.js +173 -0
  151. package/dist/tsconfig.tsbuildinfo +1 -0
  152. package/package.json +39 -0
  153. package/src/builtins/python.ts +20 -0
  154. package/src/components/Atom.tsx +76 -0
  155. package/src/components/CallSignature.tsx +251 -0
  156. package/src/components/ClassDeclaration.tsx +98 -0
  157. package/src/components/ClassInstantiation.tsx +54 -0
  158. package/src/components/Declaration.tsx +91 -0
  159. package/src/components/EnumDeclaration.tsx +291 -0
  160. package/src/components/EnumMember.tsx +92 -0
  161. package/src/components/FunctionCallExpression.tsx +36 -0
  162. package/src/components/FunctionDeclaration.tsx +121 -0
  163. package/src/components/ImportStatement.tsx +134 -0
  164. package/src/components/MemberExpression.tsx +456 -0
  165. package/src/components/NoNamePolicy.tsx +31 -0
  166. package/src/components/PyDoc.tsx +331 -0
  167. package/src/components/PythonBlock.tsx +26 -0
  168. package/src/components/Reference.tsx +21 -0
  169. package/src/components/SourceFile.tsx +93 -0
  170. package/src/components/StatementList.tsx +28 -0
  171. package/src/components/VariableDeclaration.tsx +180 -0
  172. package/src/components/index.ts +18 -0
  173. package/src/create-module.ts +102 -0
  174. package/src/index.ts +7 -0
  175. package/src/name-policy.ts +101 -0
  176. package/src/parameter-descriptor.ts +36 -0
  177. package/src/symbol-creation.ts +36 -0
  178. package/src/symbols/custom-output-scope.ts +35 -0
  179. package/src/symbols/index.ts +6 -0
  180. package/src/symbols/python-member-scope.ts +12 -0
  181. package/src/symbols/python-module-scope.ts +89 -0
  182. package/src/symbols/python-output-symbol.ts +36 -0
  183. package/src/symbols/reference.ts +99 -0
  184. package/src/symbols/scopes.ts +9 -0
  185. package/src/utils.ts +27 -0
  186. package/temp/api.json +7207 -0
  187. package/test/callsignatures.test.tsx +256 -0
  188. package/test/classdeclarations.test.tsx +320 -0
  189. package/test/classinstantiations.test.tsx +159 -0
  190. package/test/enums.test.tsx +203 -0
  191. package/test/externals.test.tsx +190 -0
  192. package/test/functioncallexpressions.test.tsx +145 -0
  193. package/test/functiondeclaration.test.tsx +327 -0
  194. package/test/imports.test.tsx +214 -0
  195. package/test/memberexpressions.test.tsx +725 -0
  196. package/test/namepolicies.test.tsx +109 -0
  197. package/test/pydocs.test.tsx +528 -0
  198. package/test/references.test.tsx +36 -0
  199. package/test/sourcefiles.test.tsx +131 -0
  200. package/test/utils.tsx +131 -0
  201. package/test/values.test.tsx +61 -0
  202. package/test/variables.test.tsx +153 -0
  203. package/tsconfig.json +12 -0
  204. package/tsdoc-metadata.json +11 -0
  205. package/vitest.config.ts +10 -0
  206. package/vitest.setup.ts +1 -0
@@ -0,0 +1,60 @@
1
+ import { memo, OutputSymbolFlags, resolve, untrack, useContext, useMemberScope } from "@alloy-js/core";
2
+ import { PythonSourceFileContext } from "../components/SourceFile.js";
3
+ export function ref(refkey) {
4
+ const sourceFile = useContext(PythonSourceFileContext);
5
+ const resolveResult = resolve(refkey);
6
+ const currentScope = useMemberScope();
7
+ return memo(() => {
8
+ if (resolveResult.value === undefined) {
9
+ return ["<Unresolved Symbol>", undefined];
10
+ }
11
+ const {
12
+ targetDeclaration,
13
+ pathDown,
14
+ memberPath
15
+ } = resolveResult.value;
16
+
17
+ // if we resolved a instance member, check if we should be able to access
18
+ // it.
19
+ if (targetDeclaration.flags & OutputSymbolFlags.InstanceMember) {
20
+ if (currentScope?.instanceMembers !== targetDeclaration.scope) {
21
+ throw new Error("Cannot resolve member symbols from a different member scope");
22
+ }
23
+ }
24
+
25
+ // Where the target declaration is relative to the referencing scope.
26
+ // * module: target symbol is in a different module
27
+ // * local: target symbol is within the current module
28
+ const targetLocation = pathDown[0]?.kind ?? "local";
29
+ let localSymbol;
30
+ if (targetLocation === "module") {
31
+ // Handling of targets in other modules, either created with createModule()
32
+ // or from other files.
33
+ const symbolPath = [...pathDown.slice(1).map(s => s.owner), targetDeclaration];
34
+ const importSymbol = symbolPath[0];
35
+ localSymbol = untrack(() => sourceFile.scope.addImport(importSymbol, pathDown[0]));
36
+ }
37
+ if (memberPath && memberPath.length > 0) {
38
+ if (localSymbol) {
39
+ memberPath[0] = localSymbol;
40
+ }
41
+ return [buildMemberExpression(memberPath), memberPath.at(-1)];
42
+ } else {
43
+ return [buildMemberExpression([localSymbol ?? targetDeclaration]), localSymbol ?? targetDeclaration];
44
+ }
45
+ });
46
+ }
47
+ function buildMemberExpression(path) {
48
+ let memberExpr = "";
49
+ const base = path[0];
50
+ if (base.flags & OutputSymbolFlags.InstanceMember) {
51
+ memberExpr += "self";
52
+ } else {
53
+ memberExpr += base.name;
54
+ path = path.slice(1);
55
+ }
56
+ for (const sym of path) {
57
+ memberExpr += `.${sym.name}`;
58
+ }
59
+ return memberExpr;
60
+ }
@@ -0,0 +1,5 @@
1
+ import { PythonMemberScope } from "./python-member-scope.js";
2
+ import { PythonModuleScope } from "./python-module-scope.js";
3
+ export type PythonOutputScope = PythonModuleScope | PythonMemberScope;
4
+ export declare function usePythonScope(): PythonOutputScope;
5
+ //# sourceMappingURL=scopes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scopes.d.ts","sourceRoot":"","sources":["../../../src/symbols/scopes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,iBAAiB,CAAC;AAEtE,wBAAgB,cAAc,IACP,iBAAiB,CACvC"}
@@ -0,0 +1,4 @@
1
+ import { useScope } from "@alloy-js/core";
2
+ export function usePythonScope() {
3
+ return useScope();
4
+ }
@@ -0,0 +1,7 @@
1
+ import { CallSignatureProps } from "./components/index.js";
2
+ /**
3
+ * Extract only the call signature props from a props object which extends
4
+ * `CallSignatureProps`. You can provide default values for the props.
5
+ */
6
+ export declare function getCallSignatureProps(props: CallSignatureProps, defaults?: Partial<CallSignatureProps>): CallSignatureProps;
7
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,kBAAkB,EACzB,QAAQ,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,sBAiBvC"}
@@ -0,0 +1,12 @@
1
+ import { defaultProps, splitProps } from "@alloy-js/core";
2
+ /**
3
+ * Extract only the call signature props from a props object which extends
4
+ * `CallSignatureProps`. You can provide default values for the props.
5
+ */
6
+ export function getCallSignatureProps(props, defaults) {
7
+ const [callSignatureProps] = splitProps(props, ["parameters", "typeParameters", "args", "kwargs", "instanceFunction", "classFunction", "returnType"]);
8
+ if (!defaults) {
9
+ return callSignatureProps;
10
+ }
11
+ return defaultProps(callSignatureProps, defaults);
12
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=callsignatures.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callsignatures.test.d.ts","sourceRoot":"","sources":["../../test/callsignatures.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,276 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { d } from "@alloy-js/core/testing";
3
+ import { describe, expect, it } from "vitest";
4
+ import * as py from "../src/index.js";
5
+ import { toSourceText } from "./utils.js";
6
+ describe("Call Signature Parameters", () => {
7
+ it("renders simple function parameters", () => {
8
+ const result = toSourceText([_$createComponent(py.CallSignatureParameters, {
9
+ parameters: ["a", "b"]
10
+ })]);
11
+ expect(result).toRenderTo(d`
12
+ a, b
13
+ `);
14
+ });
15
+ it("renders ParameterDescriptor parameters", () => {
16
+ const result = toSourceText([_$createComponent(py.CallSignatureParameters, {
17
+ parameters: [{
18
+ name: "a"
19
+ }, {
20
+ name: "b"
21
+ }]
22
+ })]);
23
+ expect(result).toRenderTo(d`
24
+ a, b
25
+ `);
26
+ });
27
+ it("renders ParameterDescriptor parameters with types", () => {
28
+ const result = toSourceText([_$createComponent(py.CallSignatureParameters, {
29
+ parameters: [{
30
+ name: "a",
31
+ type: "int"
32
+ }, {
33
+ name: "b",
34
+ type: "str"
35
+ }]
36
+ })]);
37
+ expect(result).toRenderTo(d`
38
+ a: int, b: str
39
+ `);
40
+ });
41
+ it("renders optional ParameterDescriptor parameters with types", () => {
42
+ const result = toSourceText([_$createComponent(py.CallSignatureParameters, {
43
+ parameters: [{
44
+ name: "a",
45
+ type: "int",
46
+ optional: true
47
+ }, {
48
+ name: "b",
49
+ type: "str",
50
+ optional: true
51
+ }]
52
+ })]);
53
+ expect(result).toRenderTo(d`
54
+ a: int = None, b: str = None
55
+ `);
56
+ });
57
+ it("renders optional ParameterDescriptor parameters default", () => {
58
+ const result = toSourceText([_$createComponent(py.CallSignatureParameters, {
59
+ parameters: [{
60
+ name: "a",
61
+ default: 5
62
+ }, {
63
+ name: "b",
64
+ default: "hello"
65
+ }]
66
+ })]);
67
+ expect(result).toRenderTo(d`
68
+ a=5, b="hello"
69
+ `);
70
+ });
71
+ it("renders optional ParameterDescriptor parameters with types and default", () => {
72
+ const result = toSourceText([_$createComponent(py.CallSignatureParameters, {
73
+ parameters: [{
74
+ name: "a",
75
+ type: "int",
76
+ optional: true,
77
+ default: 5
78
+ }, {
79
+ name: "b",
80
+ type: "str",
81
+ optional: true,
82
+ default: "hello"
83
+ }]
84
+ })]);
85
+ expect(result).toRenderTo(d`
86
+ a: int = 5, b: str = "hello"
87
+ `);
88
+ });
89
+ });
90
+ describe("Call Signature", () => {
91
+ it("renders a simple call signature", () => {
92
+ const result = toSourceText([_$createComponent(py.CallSignature, {
93
+ parameters: ["a", "b"]
94
+ })]);
95
+ expect(result).toRenderTo(d`
96
+ (a, b)
97
+ `);
98
+ });
99
+ it("renders a simple call signature with args and kwargs", () => {
100
+ const result = toSourceText([_$createComponent(py.CallSignature, {
101
+ parameters: ["a", "b"],
102
+ args: true,
103
+ kwargs: true
104
+ })]);
105
+ expect(result).toRenderTo(d`
106
+ (a, b, *args, **kwargs)
107
+ `);
108
+ });
109
+ it("renders a simple call signature with type parameters", () => {
110
+ const result = toSourceText([_$createComponent(py.CallSignature, {
111
+ parameters: ["a", "b"],
112
+ typeParameters: ["T", "U"]
113
+ })]);
114
+ expect(result).toRenderTo(d`
115
+ [T, U](a, b)
116
+ `);
117
+ });
118
+ it("renders a simple call signature with return type", () => {
119
+ const result = toSourceText([_$createComponent(py.CallSignature, {
120
+ parameters: ["a", "b"],
121
+ returnType: "int"
122
+ })]);
123
+ expect(result).toRenderTo(d`
124
+ (a, b) -> int
125
+ `);
126
+ });
127
+ it("renders a simple call signature for a class function", () => {
128
+ const result = toSourceText([_$createComponent(py.CallSignature, {
129
+ parameters: ["a", "b"],
130
+ classFunction: true
131
+ })]);
132
+ expect(result).toRenderTo(d`
133
+ (cls, a, b)
134
+ `);
135
+ });
136
+ it("renders a simple call signature for an instance function", () => {
137
+ const result = toSourceText([_$createComponent(py.CallSignature, {
138
+ parameters: ["a", "b"],
139
+ instanceFunction: true
140
+ })]);
141
+ expect(result).toRenderTo(d`
142
+ (self, a, b)
143
+ `);
144
+ });
145
+ it("throws an error for a call signature that's instance and class function at the same time", () => {
146
+ expect(() => toSourceText([_$createComponent(py.CallSignature, {
147
+ parameters: ["a", "b"],
148
+ instanceFunction: true,
149
+ classFunction: true
150
+ })])).toThrowError(/Cannot be both an instance function and a class function/);
151
+ });
152
+ it("renders a simple call signature with all properties", () => {
153
+ const result = toSourceText([_$createComponent(py.CallSignature, {
154
+ parameters: ["a", "b"],
155
+ instanceFunction: true,
156
+ args: true,
157
+ kwargs: true,
158
+ returnType: "int"
159
+ })]);
160
+ expect(result).toRenderTo(d`
161
+ (self, a, b, *args, **kwargs) -> int
162
+ `);
163
+ });
164
+ });
165
+ describe("Call Signature - Parameter Descriptors", () => {
166
+ it("renders a call signature with parameter descriptors", () => {
167
+ const result = toSourceText([_$createComponent(py.CallSignature, {
168
+ parameters: [{
169
+ name: "a",
170
+ type: "int"
171
+ }, {
172
+ name: "b",
173
+ type: "str"
174
+ }]
175
+ })]);
176
+ expect(result).toRenderTo(d`
177
+ (a: int, b: str)
178
+ `);
179
+ });
180
+ it("renders a call signature with parameter descriptors, args and kwargs", () => {
181
+ const result = toSourceText([_$createComponent(py.CallSignature, {
182
+ parameters: [{
183
+ name: "a",
184
+ type: "int"
185
+ }, {
186
+ name: "b",
187
+ type: "str"
188
+ }],
189
+ args: true,
190
+ kwargs: true
191
+ })]);
192
+ expect(result).toRenderTo(d`
193
+ (a: int, b: str, *args, **kwargs)
194
+ `);
195
+ });
196
+ it("renders a call signature with parameter descriptors and return type", () => {
197
+ const result = toSourceText([_$createComponent(py.CallSignature, {
198
+ parameters: [{
199
+ name: "a",
200
+ type: "int"
201
+ }, {
202
+ name: "b",
203
+ type: "str"
204
+ }],
205
+ returnType: "int"
206
+ })]);
207
+ expect(result).toRenderTo(d`
208
+ (a: int, b: str) -> int
209
+ `);
210
+ });
211
+ it("renders a call signature with parameter descriptors for a class function", () => {
212
+ const result = toSourceText([_$createComponent(py.CallSignature, {
213
+ parameters: [{
214
+ name: "a",
215
+ type: "int"
216
+ }, {
217
+ name: "b",
218
+ type: "str"
219
+ }],
220
+ classFunction: true
221
+ })]);
222
+ expect(result).toRenderTo(d`
223
+ (cls, a: int, b: str)
224
+ `);
225
+ });
226
+ it("renders a call signature with parameter descriptors for an instance function", () => {
227
+ const result = toSourceText([_$createComponent(py.CallSignature, {
228
+ parameters: [{
229
+ name: "a",
230
+ type: "int"
231
+ }, {
232
+ name: "b",
233
+ type: "str"
234
+ }],
235
+ instanceFunction: true
236
+ })]);
237
+ expect(result).toRenderTo(d`
238
+ (self, a: int, b: str)
239
+ `);
240
+ });
241
+ it("renders a call signature with all", () => {
242
+ const result = toSourceText([_$createComponent(py.CallSignature, {
243
+ parameters: [{
244
+ name: "a",
245
+ type: "int"
246
+ }, {
247
+ name: "b",
248
+ type: "str"
249
+ }],
250
+ instanceFunction: true,
251
+ args: true,
252
+ kwargs: true,
253
+ returnType: "int"
254
+ })]);
255
+ expect(result).toRenderTo(d`
256
+ (self, a: int, b: str, *args, **kwargs) -> int
257
+ `);
258
+ });
259
+ it("renders a more complex call signature with parameter descriptors", () => {
260
+ const result = toSourceText([_$createComponent(py.CallSignature, {
261
+ typeParameters: ["T", "U"],
262
+ parameters: [{
263
+ name: "a",
264
+ type: "int"
265
+ }, {
266
+ name: "b",
267
+ type: "str",
268
+ default: "default_value"
269
+ }],
270
+ returnType: "int"
271
+ })]);
272
+ expect(result).toRenderTo(d`
273
+ [T, U](a: int, b: str = "default_value") -> int
274
+ `);
275
+ });
276
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=classdeclarations.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classdeclarations.test.d.ts","sourceRoot":"","sources":["../../test/classdeclarations.test.tsx"],"names":[],"mappings":""}