@alloy-js/python 0.2.0-dev.3 → 0.2.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.
- package/dist/src/builtins/python.d.ts +3 -0
- package/dist/src/builtins/python.d.ts.map +1 -1
- package/dist/src/builtins/python.js +6 -0
- package/dist/src/builtins/python.js.map +1 -1
- package/dist/src/components/Atom.d.ts +1 -0
- package/dist/src/components/Atom.d.ts.map +1 -1
- package/dist/src/components/Atom.js +3 -0
- package/dist/src/components/Atom.js.map +1 -1
- package/dist/src/components/CallSignature.d.ts +4 -15
- package/dist/src/components/CallSignature.d.ts.map +1 -1
- package/dist/src/components/CallSignature.js +13 -67
- package/dist/src/components/CallSignature.js.map +1 -1
- package/dist/src/components/ClassMethodDeclaration.d.ts +22 -0
- package/dist/src/components/ClassMethodDeclaration.d.ts.map +1 -0
- package/dist/src/components/ClassMethodDeclaration.js +32 -0
- package/dist/src/components/ClassMethodDeclaration.js.map +1 -0
- package/dist/src/components/ConstructorDeclaration.d.ts +21 -0
- package/dist/src/components/ConstructorDeclaration.d.ts.map +1 -0
- package/dist/src/components/ConstructorDeclaration.js +35 -0
- package/dist/src/components/ConstructorDeclaration.js.map +1 -0
- package/dist/src/components/DunderMethodDeclaration.d.ts +21 -0
- package/dist/src/components/DunderMethodDeclaration.d.ts.map +1 -0
- package/dist/src/components/DunderMethodDeclaration.js +29 -0
- package/dist/src/components/DunderMethodDeclaration.js.map +1 -0
- package/dist/src/components/EnumDeclaration.d.ts +11 -32
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
- package/dist/src/components/EnumDeclaration.js +10 -48
- package/dist/src/components/EnumDeclaration.js.map +1 -1
- package/dist/src/components/EnumMember.js +3 -3
- package/dist/src/components/EnumMember.js.map +1 -1
- package/dist/src/components/FunctionBase.d.ts +48 -0
- package/dist/src/components/FunctionBase.d.ts.map +1 -0
- package/dist/src/components/FunctionBase.js +91 -0
- package/dist/src/components/FunctionBase.js.map +1 -0
- package/dist/src/components/FunctionDeclaration.d.ts +11 -31
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +22 -79
- package/dist/src/components/FunctionDeclaration.js.map +1 -1
- package/dist/src/components/MethodBase.d.ts +29 -0
- package/dist/src/components/MethodBase.d.ts.map +1 -0
- package/dist/src/components/MethodBase.js +32 -0
- package/dist/src/components/MethodBase.js.map +1 -0
- package/dist/src/components/MethodDeclaration.d.ts +22 -0
- package/dist/src/components/MethodDeclaration.d.ts.map +1 -0
- package/dist/src/components/MethodDeclaration.js +34 -0
- package/dist/src/components/MethodDeclaration.js.map +1 -0
- package/dist/src/components/PropertyDeclaration.d.ts +71 -0
- package/dist/src/components/PropertyDeclaration.d.ts.map +1 -0
- package/dist/src/components/PropertyDeclaration.js +227 -0
- package/dist/src/components/PropertyDeclaration.js.map +1 -0
- package/dist/src/components/PyDoc.d.ts +107 -42
- package/dist/src/components/PyDoc.d.ts.map +1 -1
- package/dist/src/components/PyDoc.js +845 -181
- package/dist/src/components/PyDoc.js.map +1 -1
- package/dist/src/components/SourceFile.d.ts +24 -0
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +28 -1
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/components/StaticMethodDeclaration.d.ts +22 -0
- package/dist/src/components/StaticMethodDeclaration.d.ts.map +1 -0
- package/dist/src/components/StaticMethodDeclaration.js +32 -0
- package/dist/src/components/StaticMethodDeclaration.js.map +1 -0
- package/dist/src/components/TypeArguments.d.ts +9 -0
- package/dist/src/components/TypeArguments.d.ts.map +1 -0
- package/dist/src/components/TypeArguments.js +18 -0
- package/dist/src/components/TypeArguments.js.map +1 -0
- package/dist/src/components/TypeReference.d.ts +14 -0
- package/dist/src/components/TypeReference.d.ts.map +1 -0
- package/dist/src/components/TypeReference.js +29 -0
- package/dist/src/components/TypeReference.js.map +1 -0
- package/dist/src/components/UnionTypeExpression.d.ts +1 -2
- package/dist/src/components/UnionTypeExpression.d.ts.map +1 -1
- package/dist/src/components/UnionTypeExpression.js +3 -11
- package/dist/src/components/UnionTypeExpression.js.map +1 -1
- package/dist/src/components/VariableDeclaration.d.ts.map +1 -1
- package/dist/src/components/VariableDeclaration.js +3 -3
- package/dist/src/components/VariableDeclaration.js.map +1 -1
- package/dist/src/components/index.d.ts +10 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +9 -0
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/parameter-descriptor.d.ts +1 -4
- package/dist/src/parameter-descriptor.d.ts.map +1 -1
- package/dist/src/parameter-descriptor.js +7 -1
- package/dist/src/parameter-descriptor.js.map +1 -1
- package/dist/src/symbol-creation.d.ts +4 -0
- package/dist/src/symbol-creation.d.ts.map +1 -1
- package/dist/src/symbol-creation.js +12 -0
- package/dist/src/symbol-creation.js.map +1 -1
- package/dist/src/symbols/factories.d.ts +15 -0
- package/dist/src/symbols/factories.d.ts.map +1 -0
- package/dist/src/symbols/factories.js +28 -0
- package/dist/src/symbols/factories.js.map +1 -0
- package/dist/src/symbols/index.d.ts +1 -0
- package/dist/src/symbols/index.d.ts.map +1 -1
- package/dist/src/symbols/index.js +1 -0
- package/dist/src/symbols/index.js.map +1 -1
- package/dist/src/symbols/reference.d.ts +1 -1
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +1 -1
- package/dist/src/symbols/reference.js.map +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +1 -1
- package/dist/src/utils.js.map +1 -1
- package/dist/test/callsignatures.test.js +42 -64
- package/dist/test/callsignatures.test.js.map +1 -1
- package/dist/test/class-method-declaration.test.d.ts +2 -0
- package/dist/test/class-method-declaration.test.d.ts.map +1 -0
- package/dist/test/class-method-declaration.test.js +61 -0
- package/dist/test/class-method-declaration.test.js.map +1 -0
- package/dist/test/classdeclarations.test.js +6 -8
- package/dist/test/classdeclarations.test.js.map +1 -1
- package/dist/test/constructordeclaration.test.d.ts +2 -0
- package/dist/test/constructordeclaration.test.d.ts.map +1 -0
- package/dist/test/constructordeclaration.test.js +58 -0
- package/dist/test/constructordeclaration.test.js.map +1 -0
- package/dist/test/dundermethoddeclaration.test.d.ts +2 -0
- package/dist/test/dundermethoddeclaration.test.d.ts.map +1 -0
- package/dist/test/dundermethoddeclaration.test.js +65 -0
- package/dist/test/dundermethoddeclaration.test.js.map +1 -0
- package/dist/test/enums.test.js +14 -16
- package/dist/test/enums.test.js.map +1 -1
- package/dist/test/externals.test.js +2 -4
- package/dist/test/externals.test.js.map +1 -1
- package/dist/test/factories.test.d.ts +2 -0
- package/dist/test/factories.test.d.ts.map +1 -0
- package/dist/test/factories.test.js +78 -0
- package/dist/test/factories.test.js.map +1 -0
- package/dist/test/functiondeclaration.test.js +213 -59
- package/dist/test/functiondeclaration.test.js.map +1 -1
- package/dist/test/memberexpressions.test.js +1 -1
- package/dist/test/memberexpressions.test.js.map +1 -1
- package/dist/test/methoddeclaration.test.d.ts +2 -0
- package/dist/test/methoddeclaration.test.d.ts.map +1 -0
- package/dist/test/methoddeclaration.test.js +239 -0
- package/dist/test/methoddeclaration.test.js.map +1 -0
- package/dist/test/namepolicies.test.js +1 -2
- package/dist/test/namepolicies.test.js.map +1 -1
- package/dist/test/propertydeclaration.test.d.ts +2 -0
- package/dist/test/propertydeclaration.test.d.ts.map +1 -0
- package/dist/test/propertydeclaration.test.js +229 -0
- package/dist/test/propertydeclaration.test.js.map +1 -0
- package/dist/test/pydocs.test.js +926 -126
- package/dist/test/pydocs.test.js.map +1 -1
- package/dist/test/references.test.js +1 -5
- package/dist/test/references.test.js.map +1 -1
- package/dist/test/sourcefiles.test.js +90 -1
- package/dist/test/sourcefiles.test.js.map +1 -1
- package/dist/test/staticmethoddeclaration.test.d.ts +2 -0
- package/dist/test/staticmethoddeclaration.test.d.ts.map +1 -0
- package/dist/test/staticmethoddeclaration.test.js +61 -0
- package/dist/test/staticmethoddeclaration.test.js.map +1 -0
- package/dist/test/typereference.test.d.ts +2 -0
- package/dist/test/typereference.test.d.ts.map +1 -0
- package/dist/test/typereference.test.js +51 -0
- package/dist/test/typereference.test.js.map +1 -0
- package/dist/test/uniontypeexpression.test.js +152 -15
- package/dist/test/uniontypeexpression.test.js.map +1 -1
- package/dist/test/values.test.js +35 -0
- package/dist/test/values.test.js.map +1 -1
- package/dist/test/variables.test.js +28 -19
- package/dist/test/variables.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/builtins/python.ts +7 -0
- package/src/components/Atom.tsx +4 -0
- package/src/components/CallSignature.tsx +17 -69
- package/src/components/ClassMethodDeclaration.tsx +34 -0
- package/src/components/ConstructorDeclaration.tsx +37 -0
- package/src/components/DunderMethodDeclaration.tsx +30 -0
- package/src/components/EnumDeclaration.tsx +16 -44
- package/src/components/EnumMember.tsx +3 -3
- package/src/components/FunctionBase.tsx +88 -0
- package/src/components/FunctionDeclaration.tsx +18 -82
- package/src/components/MethodBase.tsx +53 -0
- package/src/components/MethodDeclaration.tsx +27 -0
- package/src/components/PropertyDeclaration.tsx +264 -0
- package/src/components/PyDoc.tsx +795 -195
- package/src/components/SourceFile.tsx +29 -0
- package/src/components/StaticMethodDeclaration.tsx +34 -0
- package/src/components/TypeArguments.tsx +24 -0
- package/src/components/TypeReference.tsx +33 -0
- package/src/components/UnionTypeExpression.tsx +4 -15
- package/src/components/VariableDeclaration.tsx +1 -3
- package/src/components/index.ts +10 -0
- package/src/parameter-descriptor.ts +6 -5
- package/src/symbol-creation.ts +17 -0
- package/src/symbols/factories.ts +39 -0
- package/src/symbols/index.ts +1 -0
- package/src/symbols/reference.tsx +3 -5
- package/src/utils.ts +0 -2
- package/temp/api.json +5323 -2288
- package/test/callsignatures.test.tsx +102 -74
- package/test/class-method-declaration.test.tsx +53 -0
- package/test/classdeclarations.test.tsx +7 -9
- package/test/constructordeclaration.test.tsx +48 -0
- package/test/dundermethoddeclaration.test.tsx +53 -0
- package/test/enums.test.tsx +14 -16
- package/test/externals.test.tsx +5 -7
- package/test/factories.test.tsx +72 -0
- package/test/functiondeclaration.test.tsx +196 -44
- package/test/memberexpressions.test.tsx +7 -2
- package/test/methoddeclaration.test.tsx +202 -0
- package/test/namepolicies.test.tsx +1 -2
- package/test/propertydeclaration.test.tsx +192 -0
- package/test/pydocs.test.tsx +1093 -129
- package/test/references.test.tsx +1 -1
- package/test/sourcefiles.test.tsx +100 -1
- package/test/staticmethoddeclaration.test.tsx +49 -0
- package/test/typereference.test.tsx +52 -0
- package/test/uniontypeexpression.test.tsx +169 -34
- package/test/values.test.tsx +34 -0
- package/test/variables.test.tsx +27 -16
|
@@ -26,8 +26,14 @@ describe("Call Signature Parameters", () => {
|
|
|
26
26
|
const result = toSourceText([
|
|
27
27
|
<py.CallSignatureParameters
|
|
28
28
|
parameters={[
|
|
29
|
-
{
|
|
30
|
-
|
|
29
|
+
{
|
|
30
|
+
name: "a",
|
|
31
|
+
type: "int",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "b",
|
|
35
|
+
type: "str",
|
|
36
|
+
},
|
|
31
37
|
]}
|
|
32
38
|
/>,
|
|
33
39
|
]);
|
|
@@ -39,8 +45,16 @@ describe("Call Signature Parameters", () => {
|
|
|
39
45
|
const result = toSourceText([
|
|
40
46
|
<py.CallSignatureParameters
|
|
41
47
|
parameters={[
|
|
42
|
-
{
|
|
43
|
-
|
|
48
|
+
{
|
|
49
|
+
name: "a",
|
|
50
|
+
type: "int",
|
|
51
|
+
default: null,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "b",
|
|
55
|
+
type: "str",
|
|
56
|
+
default: null,
|
|
57
|
+
},
|
|
44
58
|
]}
|
|
45
59
|
/>,
|
|
46
60
|
]);
|
|
@@ -65,8 +79,16 @@ describe("Call Signature Parameters", () => {
|
|
|
65
79
|
const result = toSourceText([
|
|
66
80
|
<py.CallSignatureParameters
|
|
67
81
|
parameters={[
|
|
68
|
-
{
|
|
69
|
-
|
|
82
|
+
{
|
|
83
|
+
name: "a",
|
|
84
|
+
type: "int",
|
|
85
|
+
default: 5,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: "b",
|
|
89
|
+
type: "str",
|
|
90
|
+
default: "hello",
|
|
91
|
+
},
|
|
70
92
|
]}
|
|
71
93
|
/>,
|
|
72
94
|
]);
|
|
@@ -77,75 +99,60 @@ describe("Call Signature Parameters", () => {
|
|
|
77
99
|
});
|
|
78
100
|
|
|
79
101
|
describe("Call Signature", () => {
|
|
80
|
-
it("renders a
|
|
102
|
+
it("renders a call signature with strings", () => {
|
|
81
103
|
const result = toSourceText([<py.CallSignature parameters={["a", "b"]} />]);
|
|
82
104
|
expect(result).toRenderTo(d`
|
|
83
105
|
(a, b)
|
|
84
106
|
`);
|
|
85
107
|
});
|
|
86
|
-
it("renders a
|
|
87
|
-
const result = toSourceText([
|
|
88
|
-
<py.CallSignature parameters={["a", "b"]} args kwargs />,
|
|
89
|
-
]);
|
|
90
|
-
expect(result).toRenderTo(d`
|
|
91
|
-
(a, b, *args, **kwargs)
|
|
92
|
-
`);
|
|
93
|
-
});
|
|
94
|
-
it("renders a simple call signature with type parameters", () => {
|
|
108
|
+
it("renders a call signature with parameter descriptors", () => {
|
|
95
109
|
const result = toSourceText([
|
|
96
|
-
<py.CallSignature parameters={["a"
|
|
110
|
+
<py.CallSignature parameters={[{ name: "a" }, { name: "b" }]} />,
|
|
97
111
|
]);
|
|
98
112
|
expect(result).toRenderTo(d`
|
|
99
|
-
|
|
113
|
+
(a, b)
|
|
100
114
|
`);
|
|
101
115
|
});
|
|
102
|
-
it("renders a
|
|
116
|
+
it("renders a call signature with mixed strings and parameter descriptors", () => {
|
|
103
117
|
const result = toSourceText([
|
|
104
|
-
<py.CallSignature parameters={["a", "b"]}
|
|
118
|
+
<py.CallSignature parameters={["a", { name: "b" }]} />,
|
|
105
119
|
]);
|
|
106
120
|
expect(result).toRenderTo(d`
|
|
107
|
-
(a, b)
|
|
121
|
+
(a, b)
|
|
108
122
|
`);
|
|
109
123
|
});
|
|
110
|
-
it("renders a simple call signature
|
|
124
|
+
it("renders a simple call signature with args and kwargs", () => {
|
|
111
125
|
const result = toSourceText([
|
|
112
|
-
<py.CallSignature
|
|
126
|
+
<py.CallSignature
|
|
127
|
+
parameters={[{ name: "a" }, { name: "b" }]}
|
|
128
|
+
args
|
|
129
|
+
kwargs
|
|
130
|
+
/>,
|
|
113
131
|
]);
|
|
114
132
|
expect(result).toRenderTo(d`
|
|
115
|
-
(
|
|
133
|
+
(a, b, *args, **kwargs)
|
|
116
134
|
`);
|
|
117
135
|
});
|
|
118
|
-
it("renders a simple call signature
|
|
136
|
+
it("renders a simple call signature with type parameters", () => {
|
|
119
137
|
const result = toSourceText([
|
|
120
|
-
<py.CallSignature
|
|
138
|
+
<py.CallSignature
|
|
139
|
+
parameters={[{ name: "a" }, { name: "b" }]}
|
|
140
|
+
typeParameters={["T", "U"]}
|
|
141
|
+
/>,
|
|
121
142
|
]);
|
|
122
143
|
expect(result).toRenderTo(d`
|
|
123
|
-
|
|
144
|
+
[T, U](a, b)
|
|
124
145
|
`);
|
|
125
146
|
});
|
|
126
|
-
it("
|
|
127
|
-
expect(() =>
|
|
128
|
-
toSourceText([
|
|
129
|
-
<py.CallSignature
|
|
130
|
-
parameters={["a", "b"]}
|
|
131
|
-
instanceFunction
|
|
132
|
-
classFunction
|
|
133
|
-
/>,
|
|
134
|
-
]),
|
|
135
|
-
).toThrowError(/Cannot be both an instance function and a class function/);
|
|
136
|
-
});
|
|
137
|
-
it("renders a simple call signature with all properties", () => {
|
|
147
|
+
it("renders a simple call signature with return type", () => {
|
|
138
148
|
const result = toSourceText([
|
|
139
149
|
<py.CallSignature
|
|
140
|
-
parameters={["a", "b"]}
|
|
141
|
-
instanceFunction
|
|
142
|
-
args
|
|
143
|
-
kwargs
|
|
150
|
+
parameters={[{ name: "a" }, { name: "b" }]}
|
|
144
151
|
returnType="int"
|
|
145
152
|
/>,
|
|
146
153
|
]);
|
|
147
154
|
expect(result).toRenderTo(d`
|
|
148
|
-
(
|
|
155
|
+
(a, b) -> int
|
|
149
156
|
`);
|
|
150
157
|
});
|
|
151
158
|
});
|
|
@@ -155,8 +162,14 @@ describe("Call Signature - Parameter Descriptors", () => {
|
|
|
155
162
|
const result = toSourceText([
|
|
156
163
|
<py.CallSignature
|
|
157
164
|
parameters={[
|
|
158
|
-
{
|
|
159
|
-
|
|
165
|
+
{
|
|
166
|
+
name: "a",
|
|
167
|
+
type: "int",
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: "b",
|
|
171
|
+
type: "str",
|
|
172
|
+
},
|
|
160
173
|
]}
|
|
161
174
|
/>,
|
|
162
175
|
]);
|
|
@@ -168,8 +181,14 @@ describe("Call Signature - Parameter Descriptors", () => {
|
|
|
168
181
|
const result = toSourceText([
|
|
169
182
|
<py.CallSignature
|
|
170
183
|
parameters={[
|
|
171
|
-
{
|
|
172
|
-
|
|
184
|
+
{
|
|
185
|
+
name: "a",
|
|
186
|
+
type: "int",
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: "b",
|
|
190
|
+
type: "str",
|
|
191
|
+
},
|
|
173
192
|
]}
|
|
174
193
|
args
|
|
175
194
|
kwargs
|
|
@@ -183,8 +202,14 @@ describe("Call Signature - Parameter Descriptors", () => {
|
|
|
183
202
|
const result = toSourceText([
|
|
184
203
|
<py.CallSignature
|
|
185
204
|
parameters={[
|
|
186
|
-
{
|
|
187
|
-
|
|
205
|
+
{
|
|
206
|
+
name: "a",
|
|
207
|
+
type: "int",
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
name: "b",
|
|
211
|
+
type: "str",
|
|
212
|
+
},
|
|
188
213
|
]}
|
|
189
214
|
returnType="int"
|
|
190
215
|
/>,
|
|
@@ -197,45 +222,41 @@ describe("Call Signature - Parameter Descriptors", () => {
|
|
|
197
222
|
const result = toSourceText([
|
|
198
223
|
<py.CallSignature
|
|
199
224
|
parameters={[
|
|
200
|
-
{
|
|
201
|
-
|
|
225
|
+
{
|
|
226
|
+
name: "a",
|
|
227
|
+
type: "int",
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
name: "b",
|
|
231
|
+
type: "str",
|
|
232
|
+
},
|
|
202
233
|
]}
|
|
203
|
-
classFunction
|
|
204
234
|
/>,
|
|
205
235
|
]);
|
|
206
236
|
expect(result).toRenderTo(d`
|
|
207
|
-
(
|
|
208
|
-
`);
|
|
209
|
-
});
|
|
210
|
-
it("renders a call signature with parameter descriptors for an instance function", () => {
|
|
211
|
-
const result = toSourceText([
|
|
212
|
-
<py.CallSignature
|
|
213
|
-
parameters={[
|
|
214
|
-
{ name: "a", type: "int" },
|
|
215
|
-
{ name: "b", type: "str" },
|
|
216
|
-
]}
|
|
217
|
-
instanceFunction
|
|
218
|
-
/>,
|
|
219
|
-
]);
|
|
220
|
-
expect(result).toRenderTo(d`
|
|
221
|
-
(self, a: int, b: str)
|
|
237
|
+
(a: int, b: str)
|
|
222
238
|
`);
|
|
223
239
|
});
|
|
224
240
|
it("renders a call signature with all", () => {
|
|
225
241
|
const result = toSourceText([
|
|
226
242
|
<py.CallSignature
|
|
227
243
|
parameters={[
|
|
228
|
-
{
|
|
229
|
-
|
|
244
|
+
{
|
|
245
|
+
name: "a",
|
|
246
|
+
type: "int",
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
name: "b",
|
|
250
|
+
type: "str",
|
|
251
|
+
},
|
|
230
252
|
]}
|
|
231
|
-
instanceFunction
|
|
232
253
|
args
|
|
233
254
|
kwargs
|
|
234
255
|
returnType="int"
|
|
235
256
|
/>,
|
|
236
257
|
]);
|
|
237
258
|
expect(result).toRenderTo(d`
|
|
238
|
-
(
|
|
259
|
+
(a: int, b: str, *args, **kwargs) -> int
|
|
239
260
|
`);
|
|
240
261
|
});
|
|
241
262
|
it("renders a more complex call signature with parameter descriptors", () => {
|
|
@@ -243,8 +264,15 @@ describe("Call Signature - Parameter Descriptors", () => {
|
|
|
243
264
|
<py.CallSignature
|
|
244
265
|
typeParameters={["T", "U"]}
|
|
245
266
|
parameters={[
|
|
246
|
-
{
|
|
247
|
-
|
|
267
|
+
{
|
|
268
|
+
name: "a",
|
|
269
|
+
type: "int",
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
name: "b",
|
|
273
|
+
type: "str",
|
|
274
|
+
default: "default_value",
|
|
275
|
+
},
|
|
248
276
|
]}
|
|
249
277
|
returnType="int"
|
|
250
278
|
/>,
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { d } from "@alloy-js/core/testing";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import * as py from "../src/index.js";
|
|
4
|
+
import { toSourceText } from "./utils.js";
|
|
5
|
+
|
|
6
|
+
describe("ClassMethodDeclaration", () => {
|
|
7
|
+
it("renders async class method", () => {
|
|
8
|
+
const decl = (
|
|
9
|
+
<py.StatementList>
|
|
10
|
+
<py.ClassDeclaration name="MyClass">
|
|
11
|
+
<py.StatementList>
|
|
12
|
+
<py.ClassMethodDeclaration
|
|
13
|
+
async
|
|
14
|
+
name="create"
|
|
15
|
+
returnType={"MyClass"}
|
|
16
|
+
>
|
|
17
|
+
return cls()
|
|
18
|
+
</py.ClassMethodDeclaration>
|
|
19
|
+
</py.StatementList>
|
|
20
|
+
</py.ClassDeclaration>
|
|
21
|
+
</py.StatementList>
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
expect(toSourceText([decl])).toBe(d`
|
|
25
|
+
class MyClass:
|
|
26
|
+
@classmethod
|
|
27
|
+
async def create(cls) -> MyClass:
|
|
28
|
+
return cls()
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
`);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("renders class method with parameters", () => {
|
|
35
|
+
const parameters = [{ name: "x", type: "int" }];
|
|
36
|
+
const decl = (
|
|
37
|
+
<py.ClassDeclaration name="MyClass">
|
|
38
|
+
<py.ClassMethodDeclaration name="foo" parameters={parameters}>
|
|
39
|
+
self.attribute = "value"
|
|
40
|
+
</py.ClassMethodDeclaration>
|
|
41
|
+
</py.ClassDeclaration>
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
expect(toSourceText([decl])).toBe(d`
|
|
45
|
+
class MyClass:
|
|
46
|
+
@classmethod
|
|
47
|
+
def foo(cls, x: int):
|
|
48
|
+
self.attribute = "value"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
`);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -207,9 +207,9 @@ describe("Python Class - VariableDeclaration", () => {
|
|
|
207
207
|
<py.StatementList>
|
|
208
208
|
<py.VariableDeclaration instanceVariable name="just_name" />
|
|
209
209
|
<py.VariableDeclaration
|
|
210
|
-
instanceVariable
|
|
211
210
|
name="name_and_type"
|
|
212
211
|
type="number"
|
|
212
|
+
instanceVariable
|
|
213
213
|
/>
|
|
214
214
|
<py.VariableDeclaration
|
|
215
215
|
instanceVariable
|
|
@@ -269,9 +269,8 @@ describe("Python Class - VariableDeclaration", () => {
|
|
|
269
269
|
initializer={42}
|
|
270
270
|
instanceVariable
|
|
271
271
|
/>
|
|
272
|
-
<py.
|
|
272
|
+
<py.MethodDeclaration
|
|
273
273
|
name="instanceMethod"
|
|
274
|
-
instanceFunction
|
|
275
274
|
refkey={classMethodRk}
|
|
276
275
|
returnType="int"
|
|
277
276
|
/>
|
|
@@ -312,26 +311,24 @@ describe("Python Class - FunctionDeclaration", () => {
|
|
|
312
311
|
<py.StatementList>
|
|
313
312
|
<py.VariableDeclaration name="a" type="int" instanceVariable />
|
|
314
313
|
<py.VariableDeclaration name="b" type="int" instanceVariable />
|
|
315
|
-
<py.
|
|
314
|
+
<py.MethodDeclaration
|
|
316
315
|
name="my_method"
|
|
317
316
|
parameters={[
|
|
318
317
|
{ name: "a", type: "int" },
|
|
319
318
|
{ name: "b", type: "int" },
|
|
320
319
|
]}
|
|
321
320
|
returnType="int"
|
|
322
|
-
instanceFunction
|
|
323
321
|
refkey={methodRefkey}
|
|
324
322
|
>
|
|
325
323
|
return a + b
|
|
326
|
-
</py.
|
|
327
|
-
<py.
|
|
324
|
+
</py.MethodDeclaration>
|
|
325
|
+
<py.ClassMethodDeclaration
|
|
328
326
|
name="my_class_method"
|
|
329
|
-
classFunction
|
|
330
327
|
returnType="int"
|
|
331
328
|
refkey={classMethodRefkey}
|
|
332
329
|
>
|
|
333
330
|
pass
|
|
334
|
-
</py.
|
|
331
|
+
</py.ClassMethodDeclaration>
|
|
335
332
|
<py.FunctionDeclaration
|
|
336
333
|
name="my_standalone_function"
|
|
337
334
|
returnType="int"
|
|
@@ -352,6 +349,7 @@ describe("Python Class - FunctionDeclaration", () => {
|
|
|
352
349
|
def my_method(self, a: int, b: int) -> int:
|
|
353
350
|
return a + b
|
|
354
351
|
|
|
352
|
+
@classmethod
|
|
355
353
|
def my_class_method(cls) -> int:
|
|
356
354
|
pass
|
|
357
355
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { d } from "@alloy-js/core/testing";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import * as py from "../src/index.js";
|
|
4
|
+
import { toSourceText } from "./utils.js";
|
|
5
|
+
|
|
6
|
+
describe("ConstructorDeclaration", () => {
|
|
7
|
+
it("renders async constructor with return type", () => {
|
|
8
|
+
const decl = (
|
|
9
|
+
<py.StatementList>
|
|
10
|
+
<py.ClassDeclaration name="MyClass">
|
|
11
|
+
<py.StatementList>
|
|
12
|
+
<py.ConstructorDeclaration async returnType={"MyClass"}>
|
|
13
|
+
return super().__new__(cls)
|
|
14
|
+
</py.ConstructorDeclaration>
|
|
15
|
+
</py.StatementList>
|
|
16
|
+
</py.ClassDeclaration>
|
|
17
|
+
</py.StatementList>
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
expect(toSourceText([decl])).toBe(d`
|
|
21
|
+
class MyClass:
|
|
22
|
+
async def __new__(cls) -> MyClass:
|
|
23
|
+
return super().__new__(cls)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
`);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("renders __new__ with spread args", () => {
|
|
30
|
+
const decl = (
|
|
31
|
+
<py.ClassDeclaration name="MyClass">
|
|
32
|
+
<py.StatementList>
|
|
33
|
+
<py.ConstructorDeclaration args kwargs>
|
|
34
|
+
pass
|
|
35
|
+
</py.ConstructorDeclaration>
|
|
36
|
+
</py.StatementList>
|
|
37
|
+
</py.ClassDeclaration>
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
expect(toSourceText([decl])).toBe(d`
|
|
41
|
+
class MyClass:
|
|
42
|
+
def __new__(cls, *args, **kwargs):
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
`);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { d } from "@alloy-js/core/testing";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import * as py from "../src/index.js";
|
|
4
|
+
import { toSourceText } from "./utils.js";
|
|
5
|
+
|
|
6
|
+
describe("Dunder/Constructor Declarations", () => {
|
|
7
|
+
it("renders dunder methods with parameters", () => {
|
|
8
|
+
const parameters = [{ name: "x", type: "int" }];
|
|
9
|
+
const decl = (
|
|
10
|
+
<py.ClassDeclaration name="MyClass">
|
|
11
|
+
<py.StatementList>
|
|
12
|
+
<py.DunderMethodDeclaration name="__init__" parameters={parameters}>
|
|
13
|
+
self.attribute = "value"
|
|
14
|
+
</py.DunderMethodDeclaration>
|
|
15
|
+
<py.DunderMethodDeclaration name="__repr__" parameters={parameters}>
|
|
16
|
+
return "MyClass"
|
|
17
|
+
</py.DunderMethodDeclaration>
|
|
18
|
+
</py.StatementList>
|
|
19
|
+
</py.ClassDeclaration>
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
expect(toSourceText([decl])).toBe(d`
|
|
23
|
+
class MyClass:
|
|
24
|
+
def __init__(self, x: int):
|
|
25
|
+
self.attribute = "value"
|
|
26
|
+
|
|
27
|
+
def __repr__(self, x: int):
|
|
28
|
+
return "MyClass"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
`);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("renders dunder methods __new__", () => {
|
|
35
|
+
const decl = (
|
|
36
|
+
<py.ClassDeclaration name="MyClass">
|
|
37
|
+
<py.StatementList>
|
|
38
|
+
<py.ConstructorDeclaration args kwargs>
|
|
39
|
+
pass
|
|
40
|
+
</py.ConstructorDeclaration>
|
|
41
|
+
</py.StatementList>
|
|
42
|
+
</py.ClassDeclaration>
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
expect(toSourceText([decl])).toBe(d`
|
|
46
|
+
class MyClass:
|
|
47
|
+
def __new__(cls, *args, **kwargs):
|
|
48
|
+
pass
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
`);
|
|
52
|
+
});
|
|
53
|
+
});
|
package/test/enums.test.tsx
CHANGED
|
@@ -6,10 +6,10 @@ import * as py from "../src/index.js";
|
|
|
6
6
|
import { toSourceText } from "./utils.jsx";
|
|
7
7
|
|
|
8
8
|
describe("Python Enum", () => {
|
|
9
|
-
it("
|
|
9
|
+
it("class enum with explicit values", () => {
|
|
10
10
|
const result = toSourceText(
|
|
11
11
|
[
|
|
12
|
-
<py.
|
|
12
|
+
<py.ClassEnumDeclaration
|
|
13
13
|
name="Color"
|
|
14
14
|
baseType="IntEnum"
|
|
15
15
|
members={[
|
|
@@ -34,10 +34,10 @@ describe("Python Enum", () => {
|
|
|
34
34
|
expect(result).toRenderTo(expected);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
it("
|
|
37
|
+
it("class enum with jsValues", () => {
|
|
38
38
|
const result = toSourceText(
|
|
39
39
|
[
|
|
40
|
-
<py.
|
|
40
|
+
<py.ClassEnumDeclaration
|
|
41
41
|
name="Color"
|
|
42
42
|
baseType="IntEnum"
|
|
43
43
|
members={[
|
|
@@ -62,13 +62,13 @@ describe("Python Enum", () => {
|
|
|
62
62
|
expect(result).toRenderTo(expected);
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
it("
|
|
65
|
+
it("class enum with a refkey as jsValue", () => {
|
|
66
66
|
const result = toSourceText(
|
|
67
67
|
[
|
|
68
68
|
<py.StatementList>
|
|
69
69
|
<py.ClassDeclaration name="Dog" refkey={refkey("Dog")} />
|
|
70
70
|
<py.ClassDeclaration name="Cat" refkey={refkey("Cat")} />
|
|
71
|
-
<py.
|
|
71
|
+
<py.ClassEnumDeclaration
|
|
72
72
|
name="Animal"
|
|
73
73
|
baseType="Enum"
|
|
74
74
|
members={[
|
|
@@ -98,12 +98,12 @@ describe("Python Enum", () => {
|
|
|
98
98
|
expect(result).toRenderTo(expected);
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
-
it("enum with auto() values", () => {
|
|
101
|
+
it("class enum with auto() values", () => {
|
|
102
102
|
const result = toSourceText(
|
|
103
103
|
[
|
|
104
|
-
<py.
|
|
104
|
+
<py.ClassEnumDeclaration
|
|
105
105
|
name="Animal"
|
|
106
|
-
|
|
106
|
+
auto
|
|
107
107
|
members={[{ name: "DOG" }, { name: "CAT" }, { name: "RABBIT" }]}
|
|
108
108
|
/>,
|
|
109
109
|
],
|
|
@@ -123,13 +123,13 @@ describe("Python Enum", () => {
|
|
|
123
123
|
expect(result).toRenderTo(expected);
|
|
124
124
|
});
|
|
125
125
|
|
|
126
|
-
it("enum with mixed manual and auto() values", () => {
|
|
126
|
+
it("class enum with mixed manual and auto() values", () => {
|
|
127
127
|
const result = toSourceText(
|
|
128
128
|
[
|
|
129
|
-
<py.
|
|
129
|
+
<py.ClassEnumDeclaration
|
|
130
130
|
name="Permission"
|
|
131
131
|
baseType="Flag"
|
|
132
|
-
|
|
132
|
+
auto
|
|
133
133
|
members={[
|
|
134
134
|
{ name: "READ", value: 1 },
|
|
135
135
|
{ name: "WRITE" },
|
|
@@ -157,9 +157,8 @@ describe("Python Enum", () => {
|
|
|
157
157
|
it("functional enum with list", () => {
|
|
158
158
|
const result = toSourceText(
|
|
159
159
|
[
|
|
160
|
-
<py.
|
|
160
|
+
<py.FunctionalEnumDeclaration
|
|
161
161
|
name="Direction"
|
|
162
|
-
style="functional"
|
|
163
162
|
members={[
|
|
164
163
|
{ name: "NORTH" },
|
|
165
164
|
{ name: "SOUTH" },
|
|
@@ -181,9 +180,8 @@ describe("Python Enum", () => {
|
|
|
181
180
|
it("functional enum with mapping", () => {
|
|
182
181
|
const result = toSourceText(
|
|
183
182
|
[
|
|
184
|
-
<py.
|
|
183
|
+
<py.FunctionalEnumDeclaration
|
|
185
184
|
name="Priority"
|
|
186
|
-
style="functional"
|
|
187
185
|
members={[
|
|
188
186
|
{ name: "HIGH", value: 1 },
|
|
189
187
|
{ name: "MEDIUM", value: 2 },
|
package/test/externals.test.tsx
CHANGED
|
@@ -118,11 +118,10 @@ it("uses import from external library in multiple class methods", () => {
|
|
|
118
118
|
instanceVariable
|
|
119
119
|
refkey={refkey("some_var")}
|
|
120
120
|
/>
|
|
121
|
-
<py.
|
|
122
|
-
name="getUser"
|
|
121
|
+
<py.MethodDeclaration
|
|
122
|
+
name={"getUser"}
|
|
123
123
|
parameters={[{ name: "userId", type: "int" }]}
|
|
124
124
|
returnType={py.requestsModule["models"]["Response"]}
|
|
125
|
-
instanceFunction
|
|
126
125
|
>
|
|
127
126
|
<py.StatementList>
|
|
128
127
|
<py.VariableDeclaration
|
|
@@ -138,12 +137,11 @@ it("uses import from external library in multiple class methods", () => {
|
|
|
138
137
|
return response.json()
|
|
139
138
|
`}
|
|
140
139
|
</py.StatementList>
|
|
141
|
-
</py.
|
|
142
|
-
<py.
|
|
140
|
+
</py.MethodDeclaration>
|
|
141
|
+
<py.MethodDeclaration
|
|
143
142
|
name={"createUser"}
|
|
144
143
|
parameters={[{ name: "userName", type: "string" }]}
|
|
145
144
|
returnType={py.requestsModule["models"]["Response"]}
|
|
146
|
-
instanceFunction
|
|
147
145
|
>
|
|
148
146
|
<py.StatementList>
|
|
149
147
|
<py.VariableDeclaration
|
|
@@ -159,7 +157,7 @@ it("uses import from external library in multiple class methods", () => {
|
|
|
159
157
|
return response.json()
|
|
160
158
|
`}
|
|
161
159
|
</py.StatementList>
|
|
162
|
-
</py.
|
|
160
|
+
</py.MethodDeclaration>
|
|
163
161
|
</py.StatementList>
|
|
164
162
|
</py.ClassDeclaration>,
|
|
165
163
|
];
|