@alloy-js/python 0.3.0-dev.2 → 0.3.0-dev.4
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/components/DataclassDeclaration.d.ts.map +1 -1
- package/dist/src/components/DataclassDeclaration.js +3 -0
- package/dist/src/components/DataclassDeclaration.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/PyDoc.d.ts +9 -1
- package/dist/src/components/PyDoc.d.ts.map +1 -1
- package/dist/src/components/PyDoc.js +8 -7
- package/dist/src/components/PyDoc.js.map +1 -1
- package/dist/test/dataclassdeclarations.test.js +69 -3
- package/dist/test/dataclassdeclarations.test.js.map +1 -1
- package/dist/test/pydocs.test.js +12 -21
- package/dist/test/pydocs.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/DataclassDeclaration.tsx +6 -1
- package/src/components/EnumMember.tsx +3 -3
- package/src/components/PyDoc.tsx +22 -8
- package/temp/api.json +93 -47
- package/test/dataclassdeclarations.test.tsx +63 -2
- package/test/pydocs.test.tsx +12 -37
|
@@ -3,7 +3,7 @@ import { enumModule } from "../builtins/python.js";
|
|
|
3
3
|
import { createPythonSymbol } from "../symbol-creation.js";
|
|
4
4
|
import { PythonOutputSymbol } from "../symbols/index.js";
|
|
5
5
|
import { Atom } from "./Atom.jsx";
|
|
6
|
-
import {
|
|
6
|
+
import { InlineDoc } from "./PyDoc.jsx";
|
|
7
7
|
|
|
8
8
|
export interface EnumMemberProps {
|
|
9
9
|
/**
|
|
@@ -73,7 +73,7 @@ export function EnumMember(props: EnumMemberProps) {
|
|
|
73
73
|
<>
|
|
74
74
|
'{sym.name}'<Show when={valueCode !== undefined}> : {valueCode}</Show>
|
|
75
75
|
<Show when={props.doc !== undefined}>
|
|
76
|
-
<
|
|
76
|
+
<InlineDoc>{props.doc}</InlineDoc>
|
|
77
77
|
</Show>
|
|
78
78
|
</>
|
|
79
79
|
);
|
|
@@ -83,7 +83,7 @@ export function EnumMember(props: EnumMemberProps) {
|
|
|
83
83
|
{sym.name}
|
|
84
84
|
<Show when={valueCode !== undefined}> = {valueCode}</Show>
|
|
85
85
|
<Show when={props.doc !== undefined}>
|
|
86
|
-
<
|
|
86
|
+
<InlineDoc>{props.doc}</InlineDoc>
|
|
87
87
|
</Show>
|
|
88
88
|
</>
|
|
89
89
|
);
|
package/src/components/PyDoc.tsx
CHANGED
|
@@ -259,6 +259,28 @@ export function PyDoc(props: PyDocProps) {
|
|
|
259
259
|
);
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
+
export interface InlineDocProps {
|
|
263
|
+
children: Children;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* An inline documentation component for attribute docstrings.
|
|
268
|
+
* Unlike PyDoc, this doesn't add a trailing line break after the closing quotes,
|
|
269
|
+
* which is appropriate for documenting consecutive attributes like enum members.
|
|
270
|
+
*/
|
|
271
|
+
export function InlineDoc(props: InlineDocProps) {
|
|
272
|
+
return (
|
|
273
|
+
<>
|
|
274
|
+
<hardline />
|
|
275
|
+
{'"""'}
|
|
276
|
+
<hbr />
|
|
277
|
+
{props.children}
|
|
278
|
+
<hbr />
|
|
279
|
+
{'"""'}
|
|
280
|
+
</>
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
|
|
262
284
|
export interface PyDocExampleProps {
|
|
263
285
|
children: Children;
|
|
264
286
|
}
|
|
@@ -373,14 +395,6 @@ export interface SimpleInlineCommentProps {
|
|
|
373
395
|
children: Children;
|
|
374
396
|
}
|
|
375
397
|
|
|
376
|
-
export function SimpleInlineMemberComment(props: SimpleInlineCommentProps) {
|
|
377
|
-
return (
|
|
378
|
-
<>
|
|
379
|
-
{" "}#: <Prose>{props.children}</Prose>
|
|
380
|
-
</>
|
|
381
|
-
);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
398
|
interface GoogleStyleFunctionDocProps extends Omit<FunctionDocProps, "style"> {}
|
|
385
399
|
|
|
386
400
|
/**
|
package/temp/api.json
CHANGED
|
@@ -5431,6 +5431,99 @@
|
|
|
5431
5431
|
],
|
|
5432
5432
|
"extendsTokenRanges": []
|
|
5433
5433
|
},
|
|
5434
|
+
{
|
|
5435
|
+
"kind": "Function",
|
|
5436
|
+
"canonicalReference": "@alloy-js/python!InlineDoc:function(1)",
|
|
5437
|
+
"docComment": "/**\n * An inline documentation component for attribute docstrings.\n * Unlike PyDoc, this doesn't add a trailing line break after the closing quotes,\n * which is appropriate for documenting consecutive attributes like enum members.\n */\n",
|
|
5438
|
+
"excerptTokens": [
|
|
5439
|
+
{
|
|
5440
|
+
"kind": "Content",
|
|
5441
|
+
"text": "export declare function InlineDoc(props: "
|
|
5442
|
+
},
|
|
5443
|
+
{
|
|
5444
|
+
"kind": "Reference",
|
|
5445
|
+
"text": "InlineDocProps",
|
|
5446
|
+
"canonicalReference": "@alloy-js/python!InlineDocProps:interface"
|
|
5447
|
+
},
|
|
5448
|
+
{
|
|
5449
|
+
"kind": "Content",
|
|
5450
|
+
"text": "): "
|
|
5451
|
+
},
|
|
5452
|
+
{
|
|
5453
|
+
"kind": "Reference",
|
|
5454
|
+
"text": "Children",
|
|
5455
|
+
"canonicalReference": "@alloy-js/core!Children:type"
|
|
5456
|
+
},
|
|
5457
|
+
{
|
|
5458
|
+
"kind": "Content",
|
|
5459
|
+
"text": ";"
|
|
5460
|
+
}
|
|
5461
|
+
],
|
|
5462
|
+
"fileUrlPath": "src/components/PyDoc.tsx",
|
|
5463
|
+
"returnTypeTokenRange": {
|
|
5464
|
+
"startIndex": 3,
|
|
5465
|
+
"endIndex": 4
|
|
5466
|
+
},
|
|
5467
|
+
"releaseTag": "Public",
|
|
5468
|
+
"overloadIndex": 1,
|
|
5469
|
+
"parameters": [
|
|
5470
|
+
{
|
|
5471
|
+
"parameterName": "props",
|
|
5472
|
+
"parameterTypeTokenRange": {
|
|
5473
|
+
"startIndex": 1,
|
|
5474
|
+
"endIndex": 2
|
|
5475
|
+
},
|
|
5476
|
+
"isOptional": false
|
|
5477
|
+
}
|
|
5478
|
+
],
|
|
5479
|
+
"name": "InlineDoc"
|
|
5480
|
+
},
|
|
5481
|
+
{
|
|
5482
|
+
"kind": "Interface",
|
|
5483
|
+
"canonicalReference": "@alloy-js/python!InlineDocProps:interface",
|
|
5484
|
+
"docComment": "",
|
|
5485
|
+
"excerptTokens": [
|
|
5486
|
+
{
|
|
5487
|
+
"kind": "Content",
|
|
5488
|
+
"text": "export interface InlineDocProps "
|
|
5489
|
+
}
|
|
5490
|
+
],
|
|
5491
|
+
"fileUrlPath": "src/components/PyDoc.tsx",
|
|
5492
|
+
"releaseTag": "Public",
|
|
5493
|
+
"name": "InlineDocProps",
|
|
5494
|
+
"preserveMemberOrder": false,
|
|
5495
|
+
"members": [
|
|
5496
|
+
{
|
|
5497
|
+
"kind": "PropertySignature",
|
|
5498
|
+
"canonicalReference": "@alloy-js/python!InlineDocProps#children:member",
|
|
5499
|
+
"docComment": "",
|
|
5500
|
+
"excerptTokens": [
|
|
5501
|
+
{
|
|
5502
|
+
"kind": "Content",
|
|
5503
|
+
"text": "children: "
|
|
5504
|
+
},
|
|
5505
|
+
{
|
|
5506
|
+
"kind": "Reference",
|
|
5507
|
+
"text": "Children",
|
|
5508
|
+
"canonicalReference": "@alloy-js/core!Children:type"
|
|
5509
|
+
},
|
|
5510
|
+
{
|
|
5511
|
+
"kind": "Content",
|
|
5512
|
+
"text": ";"
|
|
5513
|
+
}
|
|
5514
|
+
],
|
|
5515
|
+
"isReadonly": false,
|
|
5516
|
+
"isOptional": false,
|
|
5517
|
+
"releaseTag": "Public",
|
|
5518
|
+
"name": "children",
|
|
5519
|
+
"propertyTypeTokenRange": {
|
|
5520
|
+
"startIndex": 1,
|
|
5521
|
+
"endIndex": 2
|
|
5522
|
+
}
|
|
5523
|
+
}
|
|
5524
|
+
],
|
|
5525
|
+
"extendsTokenRanges": []
|
|
5526
|
+
},
|
|
5434
5527
|
{
|
|
5435
5528
|
"kind": "Function",
|
|
5436
5529
|
"canonicalReference": "@alloy-js/python!isParameterDescriptor:function(1)",
|
|
@@ -9731,53 +9824,6 @@
|
|
|
9731
9824
|
],
|
|
9732
9825
|
"extendsTokenRanges": []
|
|
9733
9826
|
},
|
|
9734
|
-
{
|
|
9735
|
-
"kind": "Function",
|
|
9736
|
-
"canonicalReference": "@alloy-js/python!SimpleInlineMemberComment:function(1)",
|
|
9737
|
-
"docComment": "",
|
|
9738
|
-
"excerptTokens": [
|
|
9739
|
-
{
|
|
9740
|
-
"kind": "Content",
|
|
9741
|
-
"text": "export declare function SimpleInlineMemberComment(props: "
|
|
9742
|
-
},
|
|
9743
|
-
{
|
|
9744
|
-
"kind": "Reference",
|
|
9745
|
-
"text": "SimpleInlineCommentProps",
|
|
9746
|
-
"canonicalReference": "@alloy-js/python!SimpleInlineCommentProps:interface"
|
|
9747
|
-
},
|
|
9748
|
-
{
|
|
9749
|
-
"kind": "Content",
|
|
9750
|
-
"text": "): "
|
|
9751
|
-
},
|
|
9752
|
-
{
|
|
9753
|
-
"kind": "Reference",
|
|
9754
|
-
"text": "Children",
|
|
9755
|
-
"canonicalReference": "@alloy-js/core!Children:type"
|
|
9756
|
-
},
|
|
9757
|
-
{
|
|
9758
|
-
"kind": "Content",
|
|
9759
|
-
"text": ";"
|
|
9760
|
-
}
|
|
9761
|
-
],
|
|
9762
|
-
"fileUrlPath": "src/components/PyDoc.tsx",
|
|
9763
|
-
"returnTypeTokenRange": {
|
|
9764
|
-
"startIndex": 3,
|
|
9765
|
-
"endIndex": 4
|
|
9766
|
-
},
|
|
9767
|
-
"releaseTag": "Public",
|
|
9768
|
-
"overloadIndex": 1,
|
|
9769
|
-
"parameters": [
|
|
9770
|
-
{
|
|
9771
|
-
"parameterName": "props",
|
|
9772
|
-
"parameterTypeTokenRange": {
|
|
9773
|
-
"startIndex": 1,
|
|
9774
|
-
"endIndex": 2
|
|
9775
|
-
},
|
|
9776
|
-
"isOptional": false
|
|
9777
|
-
}
|
|
9778
|
-
],
|
|
9779
|
-
"name": "SimpleInlineMemberComment"
|
|
9780
|
-
},
|
|
9781
9827
|
{
|
|
9782
9828
|
"kind": "Function",
|
|
9783
9829
|
"canonicalReference": "@alloy-js/python!SourceFile:function(1)",
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { Prose, namekey } from "@alloy-js/core";
|
|
1
|
+
import { Prose, namekey, refkey } from "@alloy-js/core";
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
4
|
import { dataclassesModule } from "../src/builtins/python.js";
|
|
5
5
|
import * as py from "../src/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
assertFileContents,
|
|
8
|
+
toSourceText,
|
|
9
|
+
toSourceTextMultiple,
|
|
10
|
+
} from "./utils.jsx";
|
|
7
11
|
|
|
8
12
|
describe("DataclassDeclaration", () => {
|
|
9
13
|
it("Creates a dataclass with a class doc", () => {
|
|
@@ -582,4 +586,61 @@ describe("DataclassDeclaration", () => {
|
|
|
582
586
|
`,
|
|
583
587
|
);
|
|
584
588
|
});
|
|
589
|
+
|
|
590
|
+
it("Forwards refkey prop for symbol resolution in type references", () => {
|
|
591
|
+
const userRefkey = refkey();
|
|
592
|
+
const res = toSourceTextMultiple(
|
|
593
|
+
[
|
|
594
|
+
<py.SourceFile path="models.py">
|
|
595
|
+
<py.DataclassDeclaration name="User" refkey={userRefkey}>
|
|
596
|
+
<py.VariableDeclaration
|
|
597
|
+
instanceVariable
|
|
598
|
+
omitNone
|
|
599
|
+
name="id"
|
|
600
|
+
type="int"
|
|
601
|
+
/>
|
|
602
|
+
<py.VariableDeclaration
|
|
603
|
+
instanceVariable
|
|
604
|
+
omitNone
|
|
605
|
+
name="name"
|
|
606
|
+
type="str"
|
|
607
|
+
/>
|
|
608
|
+
</py.DataclassDeclaration>
|
|
609
|
+
</py.SourceFile>,
|
|
610
|
+
<py.SourceFile path="services.py">
|
|
611
|
+
<py.FunctionDeclaration name="get_user" returnType={userRefkey}>
|
|
612
|
+
<py.VariableDeclaration
|
|
613
|
+
name="user"
|
|
614
|
+
type={userRefkey}
|
|
615
|
+
initializer={
|
|
616
|
+
<py.ClassInstantiation target="User" args={["1", '"Alice"']} />
|
|
617
|
+
}
|
|
618
|
+
/>
|
|
619
|
+
<hbr />
|
|
620
|
+
{"return user"}
|
|
621
|
+
</py.FunctionDeclaration>
|
|
622
|
+
</py.SourceFile>,
|
|
623
|
+
],
|
|
624
|
+
{ externals: [dataclassesModule] },
|
|
625
|
+
);
|
|
626
|
+
assertFileContents(res, {
|
|
627
|
+
"models.py": `
|
|
628
|
+
from dataclasses import dataclass
|
|
629
|
+
|
|
630
|
+
@dataclass
|
|
631
|
+
class User:
|
|
632
|
+
id: int
|
|
633
|
+
name: str
|
|
634
|
+
|
|
635
|
+
`,
|
|
636
|
+
"services.py": `
|
|
637
|
+
from models import User
|
|
638
|
+
|
|
639
|
+
def get_user() -> User:
|
|
640
|
+
user: User = User(1, "Alice")
|
|
641
|
+
return user
|
|
642
|
+
|
|
643
|
+
`,
|
|
644
|
+
});
|
|
645
|
+
});
|
|
585
646
|
});
|
package/test/pydocs.test.tsx
CHANGED
|
@@ -195,40 +195,6 @@ describe("SimpleInlineComment", () => {
|
|
|
195
195
|
});
|
|
196
196
|
});
|
|
197
197
|
|
|
198
|
-
describe("SimpleInlineMemberComment", () => {
|
|
199
|
-
it("renders inline member comment", () => {
|
|
200
|
-
const res = toSourceText([
|
|
201
|
-
<>
|
|
202
|
-
status: int
|
|
203
|
-
<py.SimpleInlineMemberComment>
|
|
204
|
-
HTTP status code
|
|
205
|
-
</py.SimpleInlineMemberComment>
|
|
206
|
-
</>,
|
|
207
|
-
]);
|
|
208
|
-
expect(res).toRenderTo(
|
|
209
|
-
d`
|
|
210
|
-
status: int #: HTTP status code
|
|
211
|
-
`,
|
|
212
|
-
);
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it("renders inline member comment for variable declaration", () => {
|
|
216
|
-
const res = toSourceText([
|
|
217
|
-
<>
|
|
218
|
-
max_retries = 3
|
|
219
|
-
<py.SimpleInlineMemberComment>
|
|
220
|
-
Maximum number of retry attempts
|
|
221
|
-
</py.SimpleInlineMemberComment>
|
|
222
|
-
</>,
|
|
223
|
-
]);
|
|
224
|
-
expect(res).toRenderTo(
|
|
225
|
-
d`
|
|
226
|
-
max_retries = 3 #: Maximum number of retry attempts
|
|
227
|
-
`,
|
|
228
|
-
);
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
|
|
232
198
|
describe("New Documentation Components", () => {
|
|
233
199
|
it("ModuleDoc renders correctly", () => {
|
|
234
200
|
const res = toSourceText([
|
|
@@ -1177,9 +1143,18 @@ describe("Full example", () => {
|
|
|
1177
1143
|
An enum representing colors.
|
|
1178
1144
|
"""
|
|
1179
1145
|
|
|
1180
|
-
RED = 1
|
|
1181
|
-
|
|
1182
|
-
|
|
1146
|
+
RED = 1
|
|
1147
|
+
"""
|
|
1148
|
+
The color red.
|
|
1149
|
+
"""
|
|
1150
|
+
GREEN = 2
|
|
1151
|
+
"""
|
|
1152
|
+
The color green.
|
|
1153
|
+
"""
|
|
1154
|
+
BLUE = 3
|
|
1155
|
+
"""
|
|
1156
|
+
The color blue.
|
|
1157
|
+
"""
|
|
1183
1158
|
|
|
1184
1159
|
|
|
1185
1160
|
`;
|