@alloy-js/python 0.1.0-dev.2 → 0.1.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.
@@ -22,6 +22,8 @@ export interface FunctionDeclarationProps extends BaseDeclarationProps, CallSign
22
22
  * ```
23
23
  */
24
24
  export declare function FunctionDeclaration(props: FunctionDeclarationProps): import("@alloy-js/core").Children;
25
+ export interface InitFunctionDeclarationProps extends Omit<FunctionDeclarationProps, "name" | "instanceFunction" | "classFunction"> {
26
+ }
25
27
  /**
26
28
  * A Python `__init__` function declaration.
27
29
  *
@@ -43,5 +45,5 @@ export declare function FunctionDeclaration(props: FunctionDeclarationProps): im
43
45
  * an instance function, and forces the name to be `__init__` without applying
44
46
  * the name policy.
45
47
  */
46
- export declare function InitFunctionDeclaration(props: Omit<FunctionDeclarationProps, "name" | "instanceFunction" | "classFunction">): import("@alloy-js/core").Children;
48
+ export declare function InitFunctionDeclaration(props: InitFunctionDeclarationProps): import("@alloy-js/core").Children;
47
49
  //# sourceMappingURL=FunctionDeclaration.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/FunctionDeclaration.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAiB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAe,MAAM,kBAAkB,CAAC;AAIrE,MAAM,WAAW,wBACf,SAAQ,oBAAoB,EAC1B,kBAAkB;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,qCAwClE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,IAAI,CACT,wBAAwB,EACxB,MAAM,GAAG,kBAAkB,GAAG,eAAe,CAC9C,qCAYF"}
1
+ {"version":3,"file":"FunctionDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/FunctionDeclaration.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAiB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAe,MAAM,kBAAkB,CAAC;AAIrE,MAAM,WAAW,wBACf,SAAQ,oBAAoB,EAC1B,kBAAkB;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,qCAwClE;AAED,MAAM,WAAW,4BACf,SAAQ,IAAI,CACV,wBAAwB,EACxB,MAAM,GAAG,kBAAkB,GAAG,eAAe,CAC9C;CAAG;AAEN;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,4BAA4B,qCAW1E"}
@@ -72,7 +72,6 @@ export function FunctionDeclaration(props) {
72
72
  }
73
73
  }))];
74
74
  }
75
-
76
75
  /**
77
76
  * A Python `__init__` function declaration.
78
77
  *
@@ -1,4 +1,8 @@
1
1
  import { Children } from "@alloy-js/core";
2
+ export interface PythonBlockProps {
3
+ children: Children;
4
+ opener?: string;
5
+ }
2
6
  /**
3
7
  * A Python block component that can be used to render a block of Python code.
4
8
  *
@@ -16,8 +20,5 @@ import { Children } from "@alloy-js/core";
16
20
  * y: str = None
17
21
  * ```
18
22
  */
19
- export declare function PythonBlock(props: {
20
- children: Children;
21
- opener?: string;
22
- }): Children;
23
+ export declare function PythonBlock(props: PythonBlockProps): Children;
23
24
  //# sourceMappingURL=PythonBlock.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PythonBlock.d.ts","sourceRoot":"","sources":["../../../src/components/PythonBlock.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAS,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,YAMzE"}
1
+ {"version":3,"file":"PythonBlock.d.ts","sourceRoot":"","sources":["../../../src/components/PythonBlock.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAS,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,YAMlD"}
@@ -1,6 +1,5 @@
1
1
  import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
2
  import { Block } from "@alloy-js/core";
3
-
4
3
  /**
5
4
  * A Python block component that can be used to render a block of Python code.
6
5
  *
@@ -0,0 +1,7 @@
1
+ import { Children } from "@alloy-js/core";
2
+ export interface UnionTypeExpressionProps {
3
+ children: Children[];
4
+ optional?: boolean;
5
+ }
6
+ export declare function UnionTypeExpression(props: UnionTypeExpressionProps): Children;
7
+ //# sourceMappingURL=UnionTypeExpression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UnionTypeExpression.d.ts","sourceRoot":"","sources":["../../../src/components/UnionTypeExpression.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA4B,MAAM,gBAAgB,CAAC;AAEpE,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,QAAQ,EAAE,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,YAgClE"}
@@ -0,0 +1,32 @@
1
+ import { createIntrinsic as _$createIntrinsic, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { childrenArray, For, memo } from "@alloy-js/core";
3
+ export function UnionTypeExpression(props) {
4
+ const resolvedChildren = memo(() => {
5
+ const children = childrenArray(() => props.children, {
6
+ preserveFragments: true
7
+ });
8
+ if (props.optional) {
9
+ children.push("None");
10
+ }
11
+ return children;
12
+ });
13
+ return _$createIntrinsic("group", {
14
+ get children() {
15
+ return [_$createIntrinsic("ifBreak", {
16
+ children: "("
17
+ }), _$createIntrinsic("indent", {
18
+ get children() {
19
+ return [_$createIntrinsic("sbr", {}), _$createComponent(For, {
20
+ each: resolvedChildren,
21
+ get joiner() {
22
+ return [_$createIntrinsic("br", {}), "|", " "];
23
+ },
24
+ children: child => child
25
+ })];
26
+ }
27
+ }), _$createIntrinsic("sbr", {}), _$createIntrinsic("ifBreak", {
28
+ children: ")"
29
+ })];
30
+ }
31
+ });
32
+ }
@@ -15,5 +15,6 @@ export * from "./PythonBlock.js";
15
15
  export * from "./Reference.js";
16
16
  export * from "./SourceFile.js";
17
17
  export * from "./StatementList.js";
18
+ export * from "./UnionTypeExpression.js";
18
19
  export * from "./VariableDeclaration.js";
19
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC"}
@@ -15,4 +15,5 @@ export * from "./PythonBlock.js";
15
15
  export * from "./Reference.js";
16
16
  export * from "./SourceFile.js";
17
17
  export * from "./StatementList.js";
18
+ export * from "./UnionTypeExpression.js";
18
19
  export * from "./VariableDeclaration.js";
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=uniontypeexpression.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uniontypeexpression.test.d.ts","sourceRoot":"","sources":["../../test/uniontypeexpression.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1,54 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { code } from "@alloy-js/core";
3
+ import { d } from "@alloy-js/core/testing";
4
+ import { describe, expect, it } from "vitest";
5
+ import * as py from "../src/index.js";
6
+ import { toSourceText } from "./utils.js";
7
+ describe("UnionTypeExpression", () => {
8
+ it("renders a Python union expression - 1 item", () => {
9
+ const elements = [code`int`];
10
+ expect(toSourceText([_$createComponent(py.UnionTypeExpression, {
11
+ children: elements
12
+ })])).toRenderTo("int");
13
+ });
14
+ it("renders a Python union expression - 2 items", () => {
15
+ const elements = [code`int`, code`str`];
16
+ expect(toSourceText([_$createComponent(py.UnionTypeExpression, {
17
+ children: elements
18
+ })])).toRenderTo("int | str");
19
+ });
20
+ it("renders a Python union expression - N items", () => {
21
+ const elements = [code`int`, code`str`, code`float`, code`bool`, code`list`, code`dict`, code`set`, code`tuple`, code`frozenset`, code`bytes`, code`bytearray`, code`memoryview`, code`complex`];
22
+ expect(toSourceText([_$createComponent(py.UnionTypeExpression, {
23
+ children: elements
24
+ })])).toRenderTo(d`
25
+ (
26
+ int
27
+ | str
28
+ | float
29
+ | bool
30
+ | list
31
+ | dict
32
+ | set
33
+ | tuple
34
+ | frozenset
35
+ | bytes
36
+ | bytearray
37
+ | memoryview
38
+ | complex
39
+ )`);
40
+ });
41
+ it("renders a Python union expression - 2 items", () => {
42
+ const elements = [code`int`, code`str`];
43
+ expect(toSourceText([_$createComponent(py.UnionTypeExpression, {
44
+ children: elements
45
+ })])).toRenderTo("int | str");
46
+ });
47
+ it("renders a Python union expression - 2 items with optional", () => {
48
+ const elements = [code`int`, code`str`];
49
+ expect(toSourceText([_$createComponent(py.UnionTypeExpression, {
50
+ optional: true,
51
+ children: elements
52
+ })])).toRenderTo("int | str | None");
53
+ });
54
+ });
@@ -1,5 +1,5 @@
1
1
  import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import { refkey } from "@alloy-js/core";
2
+ import { code, refkey } from "@alloy-js/core";
3
3
  import { d } from "@alloy-js/core/testing";
4
4
  import { describe, expect, it } from "vitest";
5
5
  import * as py from "../src/index.js";
@@ -95,6 +95,41 @@ describe("Python Variable", () => {
95
95
  })]);
96
96
  expect(res).toBe(`12`);
97
97
  });
98
+ it("declares a python variable with an optional type", () => {
99
+ const elements = [code`int`];
100
+ const typing = _$createComponent(py.UnionTypeExpression, {
101
+ optional: true,
102
+ children: elements
103
+ });
104
+ const res = toSourceText([_$createComponent(py.StatementList, {
105
+ get children() {
106
+ return _$createComponent(py.VariableDeclaration, {
107
+ name: "my_var",
108
+ type: typing
109
+ });
110
+ }
111
+ })]);
112
+ expect(res).toBe(d`
113
+ my_var: int | None = None`);
114
+ });
115
+ it("declares a python variable with an optional type omitting none", () => {
116
+ const elements = [code`int`];
117
+ const typing = _$createComponent(py.UnionTypeExpression, {
118
+ optional: true,
119
+ children: elements
120
+ });
121
+ const res = toSourceText([_$createComponent(py.StatementList, {
122
+ get children() {
123
+ return _$createComponent(py.VariableDeclaration, {
124
+ name: "my_var",
125
+ type: typing,
126
+ omitNone: true
127
+ });
128
+ }
129
+ })]);
130
+ expect(res).toBe(d`
131
+ my_var: int | None`);
132
+ });
98
133
  it("declares a python variable with a class type", () => {
99
134
  const res = toSourceText([_$createComponent(py.StatementList, {
100
135
  get children() {