@alloy-js/python 0.2.0-dev.2 → 0.2.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/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/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/MemberExpression.d.ts.map +1 -1
- package/dist/src/components/MemberExpression.js +12 -13
- package/dist/src/components/MemberExpression.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/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/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/MemberExpression.tsx +6 -19
- 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 +5281 -2273
- 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/variables.test.tsx +27 -16
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { abcModule } from "../builtins/python.js";
|
|
2
|
+
import {
|
|
3
|
+
BaseFunctionDeclaration,
|
|
4
|
+
BaseFunctionDeclarationProps,
|
|
5
|
+
CommonFunctionProps,
|
|
6
|
+
} from "./FunctionBase.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Shared base props for all method-like declarations.
|
|
10
|
+
*/
|
|
11
|
+
export interface MethodDeclarationBaseProps extends CommonFunctionProps {
|
|
12
|
+
/** Indicates that the method is abstract. */
|
|
13
|
+
abstract?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Internal base for method-like components.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Applies `@abstractmethod` when requested and delegates to
|
|
21
|
+
* `BaseFunctionDeclaration` for the function/method body.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* <MethodDeclarationBase name="do_work" functionType="instance">
|
|
26
|
+
* return 1
|
|
27
|
+
* </MethodDeclarationBase>
|
|
28
|
+
* ```
|
|
29
|
+
* Generates:
|
|
30
|
+
* ```python
|
|
31
|
+
* def do_work(self):
|
|
32
|
+
* return 1
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function MethodDeclarationBase(
|
|
36
|
+
props: MethodDeclarationBaseProps &
|
|
37
|
+
Pick<BaseFunctionDeclarationProps, "functionType" | "sym">,
|
|
38
|
+
) {
|
|
39
|
+
const abstractMethod =
|
|
40
|
+
props.abstract ?
|
|
41
|
+
<>
|
|
42
|
+
@{abcModule["."].abstractmethod}
|
|
43
|
+
<hbr />
|
|
44
|
+
</>
|
|
45
|
+
: undefined;
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<>
|
|
49
|
+
{abstractMethod}
|
|
50
|
+
<BaseFunctionDeclaration {...props} />
|
|
51
|
+
</>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createMethodSymbol } from "../symbols/factories.js";
|
|
2
|
+
import type { MethodDeclarationBaseProps } from "./MethodBase.js";
|
|
3
|
+
import { MethodDeclarationBase } from "./MethodBase.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A Python instance method declaration component.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <py.MethodDeclaration name="do_work" parameters={[{ name: "value", type: "int" }]}>
|
|
11
|
+
* return value * 2
|
|
12
|
+
* </py.MethodDeclaration>
|
|
13
|
+
* ```
|
|
14
|
+
* Generates:
|
|
15
|
+
* ```python
|
|
16
|
+
* def do_work(self, value: int) -> None:
|
|
17
|
+
* return value * 2
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* Automatically injects the `self` parameter for instance methods and enforces
|
|
22
|
+
* that the declaration appears within a class body.
|
|
23
|
+
*/
|
|
24
|
+
export function MethodDeclaration(props: MethodDeclarationBaseProps) {
|
|
25
|
+
const sym = createMethodSymbol(props.name, { refkeys: props.refkey });
|
|
26
|
+
return <MethodDeclarationBase functionType="instance" {...props} sym={sym} />;
|
|
27
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
DeclarationContext,
|
|
4
|
+
List,
|
|
5
|
+
Refkey,
|
|
6
|
+
Show,
|
|
7
|
+
childrenArray,
|
|
8
|
+
code,
|
|
9
|
+
createContext,
|
|
10
|
+
findKeyedChild,
|
|
11
|
+
findUnkeyedChildren,
|
|
12
|
+
taggedComponent,
|
|
13
|
+
useContext,
|
|
14
|
+
} from "@alloy-js/core";
|
|
15
|
+
import { PythonOutputSymbol } from "../index.js";
|
|
16
|
+
import { ParameterDescriptor } from "../parameter-descriptor.js";
|
|
17
|
+
import { createMethodSymbol } from "../symbols/factories.js";
|
|
18
|
+
import { Atom } from "./Atom.jsx";
|
|
19
|
+
import { CommonFunctionProps } from "./FunctionBase.js";
|
|
20
|
+
import { MethodDeclarationBase } from "./MethodBase.js";
|
|
21
|
+
|
|
22
|
+
const setterTag = Symbol();
|
|
23
|
+
const deleterTag = Symbol();
|
|
24
|
+
|
|
25
|
+
/** Context to provide property type information within a PropertyDeclaration */
|
|
26
|
+
const PropertyContext = createContext<Children | undefined>();
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Declares a Python property with optional getter, setter, and deleter methods.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* <py.PropertyDeclaration name="name" type={{ children: "str" }}>
|
|
34
|
+
* return self._name
|
|
35
|
+
* </py.PropertyDeclaration>
|
|
36
|
+
* ```
|
|
37
|
+
* Generates:
|
|
38
|
+
* ```python
|
|
39
|
+
* @property
|
|
40
|
+
* def name(self) -> str:
|
|
41
|
+
* return self._name
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @example Setter and deleter
|
|
45
|
+
* ```tsx
|
|
46
|
+
* <py.PropertyDeclaration name="value" type={{ children: "int" }}>
|
|
47
|
+
* return self._value
|
|
48
|
+
* <py.PropertyDeclaration.Setter type={{ children: "int" }}>
|
|
49
|
+
* self._value = value
|
|
50
|
+
* </py.PropertyDeclaration.Setter>
|
|
51
|
+
* <py.PropertyDeclaration.Deleter>
|
|
52
|
+
* del self._value
|
|
53
|
+
* </py.PropertyDeclaration.Deleter>
|
|
54
|
+
* </py.PropertyDeclaration>
|
|
55
|
+
* ```
|
|
56
|
+
* Generates:
|
|
57
|
+
* ```python
|
|
58
|
+
* @property
|
|
59
|
+
* def value(self) -> int:
|
|
60
|
+
* return self._value
|
|
61
|
+
*
|
|
62
|
+
* @value.setter
|
|
63
|
+
* def value(self, value: int) -> None:
|
|
64
|
+
* self._value = value
|
|
65
|
+
*
|
|
66
|
+
* @value.deleter
|
|
67
|
+
* def value(self) -> None:
|
|
68
|
+
* del self._value
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @remarks
|
|
72
|
+
* The property must be declared within a class. The getter method is
|
|
73
|
+
* automatically generated using the `@property` decorator. Use the nested
|
|
74
|
+
* `Setter` and `Deleter` components to add mutators.
|
|
75
|
+
*/
|
|
76
|
+
export interface PropertyDeclarationProps {
|
|
77
|
+
name: string;
|
|
78
|
+
type?: Children;
|
|
79
|
+
children?: Children;
|
|
80
|
+
refkey?: Refkey;
|
|
81
|
+
abstract?: boolean;
|
|
82
|
+
doc?: Children;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function PropertyDeclaration(props: PropertyDeclarationProps) {
|
|
86
|
+
const nonEmptyOrNotImplemented = (
|
|
87
|
+
children: Children | undefined,
|
|
88
|
+
): Children => {
|
|
89
|
+
if (children && childrenArray(() => children).length > 0) {
|
|
90
|
+
return children;
|
|
91
|
+
} else {
|
|
92
|
+
return [code`raise NotImplementedError`];
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const children = childrenArray(() => props.children);
|
|
97
|
+
const setterComponent =
|
|
98
|
+
findKeyedChild(children, PropertyDeclaration.Setter.tag) ?? undefined;
|
|
99
|
+
const deleterComponent =
|
|
100
|
+
findKeyedChild(children, PropertyDeclaration.Deleter.tag) ?? undefined;
|
|
101
|
+
|
|
102
|
+
const setterChildren = nonEmptyOrNotImplemented(
|
|
103
|
+
setterComponent?.props?.children,
|
|
104
|
+
);
|
|
105
|
+
const deleterChildren = nonEmptyOrNotImplemented(
|
|
106
|
+
deleterComponent?.props?.children,
|
|
107
|
+
);
|
|
108
|
+
const unkeyedChildren = nonEmptyOrNotImplemented(
|
|
109
|
+
findUnkeyedChildren(children),
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const sym: PythonOutputSymbol = createMethodSymbol(props.name, {
|
|
113
|
+
refkeys: props.refkey,
|
|
114
|
+
});
|
|
115
|
+
return (
|
|
116
|
+
<>
|
|
117
|
+
<DeclarationContext.Provider value={sym}>
|
|
118
|
+
<PropertyContext.Provider value={props.type}>
|
|
119
|
+
<List hardline enderPunctuation>
|
|
120
|
+
<PropertyMethodDeclaration
|
|
121
|
+
abstract={props.abstract}
|
|
122
|
+
doc={props.doc}
|
|
123
|
+
>
|
|
124
|
+
{unkeyedChildren}
|
|
125
|
+
</PropertyMethodDeclaration>
|
|
126
|
+
<Show when={Boolean(setterComponent)}>
|
|
127
|
+
<PropertyDeclaration.Setter
|
|
128
|
+
{...setterComponent?.props}
|
|
129
|
+
type={setterComponent?.props?.type ?? props.type}
|
|
130
|
+
abstract={setterComponent?.props?.abstract ?? props.abstract}
|
|
131
|
+
>
|
|
132
|
+
{setterChildren}
|
|
133
|
+
</PropertyDeclaration.Setter>
|
|
134
|
+
</Show>
|
|
135
|
+
<Show when={Boolean(deleterComponent)}>
|
|
136
|
+
<PropertyDeclaration.Deleter
|
|
137
|
+
{...deleterComponent?.props}
|
|
138
|
+
abstract={deleterComponent?.props?.abstract ?? props.abstract}
|
|
139
|
+
>
|
|
140
|
+
{deleterChildren}
|
|
141
|
+
</PropertyDeclaration.Deleter>
|
|
142
|
+
</Show>
|
|
143
|
+
</List>
|
|
144
|
+
</PropertyContext.Provider>
|
|
145
|
+
</DeclarationContext.Provider>
|
|
146
|
+
</>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface PropertyMethodDeclarationProps
|
|
151
|
+
extends Omit<CommonFunctionProps, "name"> {
|
|
152
|
+
abstract?: boolean;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function PropertyMethodDeclaration(props: PropertyMethodDeclarationProps) {
|
|
156
|
+
const propertySymbol = useContext(DeclarationContext) as PythonOutputSymbol;
|
|
157
|
+
const propertyType = useContext(PropertyContext);
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<>
|
|
161
|
+
{code`@property`}
|
|
162
|
+
<hbr />
|
|
163
|
+
<MethodDeclarationBase
|
|
164
|
+
{...props}
|
|
165
|
+
name={propertySymbol.name}
|
|
166
|
+
functionType="instance"
|
|
167
|
+
returnType={propertyType}
|
|
168
|
+
sym={propertySymbol}
|
|
169
|
+
>
|
|
170
|
+
{props.children}
|
|
171
|
+
</MethodDeclarationBase>
|
|
172
|
+
</>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
interface PropertyMethodBaseProps
|
|
177
|
+
extends Omit<PropertyMethodDeclarationProps, "name"> {
|
|
178
|
+
decoratorType: "setter" | "deleter";
|
|
179
|
+
parameters?: (ParameterDescriptor | string)[];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function PropertyMethodBase(props: PropertyMethodBaseProps) {
|
|
183
|
+
const propertySymbol = useContext(DeclarationContext) as PythonOutputSymbol;
|
|
184
|
+
const { decoratorType, parameters, children, ...restProps } = props;
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<>
|
|
188
|
+
{code`@${propertySymbol.name}.${decoratorType}`}
|
|
189
|
+
<hbr />
|
|
190
|
+
<MethodDeclarationBase
|
|
191
|
+
{...restProps}
|
|
192
|
+
name={propertySymbol.name}
|
|
193
|
+
functionType="instance"
|
|
194
|
+
parameters={parameters}
|
|
195
|
+
returnType={<Atom jsValue={null} />}
|
|
196
|
+
sym={propertySymbol}
|
|
197
|
+
>
|
|
198
|
+
{children}
|
|
199
|
+
</MethodDeclarationBase>
|
|
200
|
+
</>
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Adds a setter to a `PropertyDeclaration`.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```tsx
|
|
209
|
+
* <py.PropertyDeclaration name="value" type={{ children: "int" }}>
|
|
210
|
+
* return self._value
|
|
211
|
+
* <py.PropertyDeclaration.Setter type={{ children: "int" }}>
|
|
212
|
+
* self._value = value
|
|
213
|
+
* </py.PropertyDeclaration.Setter>
|
|
214
|
+
* </py.PropertyDeclaration>
|
|
215
|
+
* ```
|
|
216
|
+
* Generates:
|
|
217
|
+
* ```python
|
|
218
|
+
* @value.setter
|
|
219
|
+
* def value(self, value: int) -> None:
|
|
220
|
+
* self._value = value
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
PropertyDeclaration.Setter = taggedComponent(
|
|
224
|
+
setterTag,
|
|
225
|
+
function PropertySetter(
|
|
226
|
+
props: PropertyMethodDeclarationProps & { type?: Children },
|
|
227
|
+
) {
|
|
228
|
+
return (
|
|
229
|
+
<PropertyMethodBase
|
|
230
|
+
decoratorType="setter"
|
|
231
|
+
parameters={[{ name: "value", type: props.type }]}
|
|
232
|
+
{...props}
|
|
233
|
+
/>
|
|
234
|
+
);
|
|
235
|
+
},
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Adds a deleter to a `PropertyDeclaration`.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```tsx
|
|
243
|
+
* <py.PropertyDeclaration name="value" type={{ children: "int" }}>
|
|
244
|
+
* return self._value
|
|
245
|
+
* <py.PropertyDeclaration.Deleter>
|
|
246
|
+
* del self._value
|
|
247
|
+
* </py.PropertyDeclaration.Deleter>
|
|
248
|
+
* </py.PropertyDeclaration>
|
|
249
|
+
* ```
|
|
250
|
+
* Generates:
|
|
251
|
+
* ```python
|
|
252
|
+
* @value.deleter
|
|
253
|
+
* def value(self) -> None:
|
|
254
|
+
* del self._value
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
PropertyDeclaration.Deleter = taggedComponent(
|
|
258
|
+
deleterTag,
|
|
259
|
+
function PropertyDeleter(
|
|
260
|
+
props: Omit<PropertyMethodDeclarationProps, "returnType">,
|
|
261
|
+
) {
|
|
262
|
+
return <PropertyMethodBase decoratorType="deleter" {...props} />;
|
|
263
|
+
},
|
|
264
|
+
);
|