@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.
Files changed (209) hide show
  1. package/dist/src/builtins/python.d.ts +3 -0
  2. package/dist/src/builtins/python.d.ts.map +1 -1
  3. package/dist/src/builtins/python.js +6 -0
  4. package/dist/src/builtins/python.js.map +1 -1
  5. package/dist/src/components/CallSignature.d.ts +4 -15
  6. package/dist/src/components/CallSignature.d.ts.map +1 -1
  7. package/dist/src/components/CallSignature.js +13 -67
  8. package/dist/src/components/CallSignature.js.map +1 -1
  9. package/dist/src/components/ClassMethodDeclaration.d.ts +22 -0
  10. package/dist/src/components/ClassMethodDeclaration.d.ts.map +1 -0
  11. package/dist/src/components/ClassMethodDeclaration.js +32 -0
  12. package/dist/src/components/ClassMethodDeclaration.js.map +1 -0
  13. package/dist/src/components/ConstructorDeclaration.d.ts +21 -0
  14. package/dist/src/components/ConstructorDeclaration.d.ts.map +1 -0
  15. package/dist/src/components/ConstructorDeclaration.js +35 -0
  16. package/dist/src/components/ConstructorDeclaration.js.map +1 -0
  17. package/dist/src/components/DunderMethodDeclaration.d.ts +21 -0
  18. package/dist/src/components/DunderMethodDeclaration.d.ts.map +1 -0
  19. package/dist/src/components/DunderMethodDeclaration.js +29 -0
  20. package/dist/src/components/DunderMethodDeclaration.js.map +1 -0
  21. package/dist/src/components/EnumDeclaration.d.ts +11 -32
  22. package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
  23. package/dist/src/components/EnumDeclaration.js +10 -48
  24. package/dist/src/components/EnumDeclaration.js.map +1 -1
  25. package/dist/src/components/EnumMember.js +3 -3
  26. package/dist/src/components/EnumMember.js.map +1 -1
  27. package/dist/src/components/FunctionBase.d.ts +48 -0
  28. package/dist/src/components/FunctionBase.d.ts.map +1 -0
  29. package/dist/src/components/FunctionBase.js +91 -0
  30. package/dist/src/components/FunctionBase.js.map +1 -0
  31. package/dist/src/components/FunctionDeclaration.d.ts +11 -31
  32. package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
  33. package/dist/src/components/FunctionDeclaration.js +22 -79
  34. package/dist/src/components/FunctionDeclaration.js.map +1 -1
  35. package/dist/src/components/MemberExpression.d.ts.map +1 -1
  36. package/dist/src/components/MemberExpression.js +12 -13
  37. package/dist/src/components/MemberExpression.js.map +1 -1
  38. package/dist/src/components/MethodBase.d.ts +29 -0
  39. package/dist/src/components/MethodBase.d.ts.map +1 -0
  40. package/dist/src/components/MethodBase.js +32 -0
  41. package/dist/src/components/MethodBase.js.map +1 -0
  42. package/dist/src/components/MethodDeclaration.d.ts +22 -0
  43. package/dist/src/components/MethodDeclaration.d.ts.map +1 -0
  44. package/dist/src/components/MethodDeclaration.js +34 -0
  45. package/dist/src/components/MethodDeclaration.js.map +1 -0
  46. package/dist/src/components/PropertyDeclaration.d.ts +71 -0
  47. package/dist/src/components/PropertyDeclaration.d.ts.map +1 -0
  48. package/dist/src/components/PropertyDeclaration.js +227 -0
  49. package/dist/src/components/PropertyDeclaration.js.map +1 -0
  50. package/dist/src/components/PyDoc.d.ts +107 -42
  51. package/dist/src/components/PyDoc.d.ts.map +1 -1
  52. package/dist/src/components/PyDoc.js +845 -181
  53. package/dist/src/components/PyDoc.js.map +1 -1
  54. package/dist/src/components/SourceFile.d.ts +24 -0
  55. package/dist/src/components/SourceFile.d.ts.map +1 -1
  56. package/dist/src/components/SourceFile.js +28 -1
  57. package/dist/src/components/SourceFile.js.map +1 -1
  58. package/dist/src/components/StaticMethodDeclaration.d.ts +22 -0
  59. package/dist/src/components/StaticMethodDeclaration.d.ts.map +1 -0
  60. package/dist/src/components/StaticMethodDeclaration.js +32 -0
  61. package/dist/src/components/StaticMethodDeclaration.js.map +1 -0
  62. package/dist/src/components/TypeArguments.d.ts +9 -0
  63. package/dist/src/components/TypeArguments.d.ts.map +1 -0
  64. package/dist/src/components/TypeArguments.js +18 -0
  65. package/dist/src/components/TypeArguments.js.map +1 -0
  66. package/dist/src/components/TypeReference.d.ts +14 -0
  67. package/dist/src/components/TypeReference.d.ts.map +1 -0
  68. package/dist/src/components/TypeReference.js +29 -0
  69. package/dist/src/components/TypeReference.js.map +1 -0
  70. package/dist/src/components/UnionTypeExpression.d.ts +1 -2
  71. package/dist/src/components/UnionTypeExpression.d.ts.map +1 -1
  72. package/dist/src/components/UnionTypeExpression.js +3 -11
  73. package/dist/src/components/UnionTypeExpression.js.map +1 -1
  74. package/dist/src/components/VariableDeclaration.d.ts.map +1 -1
  75. package/dist/src/components/VariableDeclaration.js +3 -3
  76. package/dist/src/components/VariableDeclaration.js.map +1 -1
  77. package/dist/src/components/index.d.ts +10 -0
  78. package/dist/src/components/index.d.ts.map +1 -1
  79. package/dist/src/components/index.js +9 -0
  80. package/dist/src/components/index.js.map +1 -1
  81. package/dist/src/parameter-descriptor.d.ts +1 -4
  82. package/dist/src/parameter-descriptor.d.ts.map +1 -1
  83. package/dist/src/parameter-descriptor.js +7 -1
  84. package/dist/src/parameter-descriptor.js.map +1 -1
  85. package/dist/src/symbol-creation.d.ts +4 -0
  86. package/dist/src/symbol-creation.d.ts.map +1 -1
  87. package/dist/src/symbol-creation.js +12 -0
  88. package/dist/src/symbol-creation.js.map +1 -1
  89. package/dist/src/symbols/factories.d.ts +15 -0
  90. package/dist/src/symbols/factories.d.ts.map +1 -0
  91. package/dist/src/symbols/factories.js +28 -0
  92. package/dist/src/symbols/factories.js.map +1 -0
  93. package/dist/src/symbols/index.d.ts +1 -0
  94. package/dist/src/symbols/index.d.ts.map +1 -1
  95. package/dist/src/symbols/index.js +1 -0
  96. package/dist/src/symbols/index.js.map +1 -1
  97. package/dist/src/symbols/reference.d.ts +1 -1
  98. package/dist/src/symbols/reference.d.ts.map +1 -1
  99. package/dist/src/symbols/reference.js +1 -1
  100. package/dist/src/symbols/reference.js.map +1 -1
  101. package/dist/src/utils.d.ts.map +1 -1
  102. package/dist/src/utils.js +1 -1
  103. package/dist/src/utils.js.map +1 -1
  104. package/dist/test/callsignatures.test.js +42 -64
  105. package/dist/test/callsignatures.test.js.map +1 -1
  106. package/dist/test/class-method-declaration.test.d.ts +2 -0
  107. package/dist/test/class-method-declaration.test.d.ts.map +1 -0
  108. package/dist/test/class-method-declaration.test.js +61 -0
  109. package/dist/test/class-method-declaration.test.js.map +1 -0
  110. package/dist/test/classdeclarations.test.js +6 -8
  111. package/dist/test/classdeclarations.test.js.map +1 -1
  112. package/dist/test/constructordeclaration.test.d.ts +2 -0
  113. package/dist/test/constructordeclaration.test.d.ts.map +1 -0
  114. package/dist/test/constructordeclaration.test.js +58 -0
  115. package/dist/test/constructordeclaration.test.js.map +1 -0
  116. package/dist/test/dundermethoddeclaration.test.d.ts +2 -0
  117. package/dist/test/dundermethoddeclaration.test.d.ts.map +1 -0
  118. package/dist/test/dundermethoddeclaration.test.js +65 -0
  119. package/dist/test/dundermethoddeclaration.test.js.map +1 -0
  120. package/dist/test/enums.test.js +14 -16
  121. package/dist/test/enums.test.js.map +1 -1
  122. package/dist/test/externals.test.js +2 -4
  123. package/dist/test/externals.test.js.map +1 -1
  124. package/dist/test/factories.test.d.ts +2 -0
  125. package/dist/test/factories.test.d.ts.map +1 -0
  126. package/dist/test/factories.test.js +78 -0
  127. package/dist/test/factories.test.js.map +1 -0
  128. package/dist/test/functiondeclaration.test.js +213 -59
  129. package/dist/test/functiondeclaration.test.js.map +1 -1
  130. package/dist/test/memberexpressions.test.js +1 -1
  131. package/dist/test/memberexpressions.test.js.map +1 -1
  132. package/dist/test/methoddeclaration.test.d.ts +2 -0
  133. package/dist/test/methoddeclaration.test.d.ts.map +1 -0
  134. package/dist/test/methoddeclaration.test.js +239 -0
  135. package/dist/test/methoddeclaration.test.js.map +1 -0
  136. package/dist/test/namepolicies.test.js +1 -2
  137. package/dist/test/namepolicies.test.js.map +1 -1
  138. package/dist/test/propertydeclaration.test.d.ts +2 -0
  139. package/dist/test/propertydeclaration.test.d.ts.map +1 -0
  140. package/dist/test/propertydeclaration.test.js +229 -0
  141. package/dist/test/propertydeclaration.test.js.map +1 -0
  142. package/dist/test/pydocs.test.js +926 -126
  143. package/dist/test/pydocs.test.js.map +1 -1
  144. package/dist/test/references.test.js +1 -5
  145. package/dist/test/references.test.js.map +1 -1
  146. package/dist/test/sourcefiles.test.js +90 -1
  147. package/dist/test/sourcefiles.test.js.map +1 -1
  148. package/dist/test/staticmethoddeclaration.test.d.ts +2 -0
  149. package/dist/test/staticmethoddeclaration.test.d.ts.map +1 -0
  150. package/dist/test/staticmethoddeclaration.test.js +61 -0
  151. package/dist/test/staticmethoddeclaration.test.js.map +1 -0
  152. package/dist/test/typereference.test.d.ts +2 -0
  153. package/dist/test/typereference.test.d.ts.map +1 -0
  154. package/dist/test/typereference.test.js +51 -0
  155. package/dist/test/typereference.test.js.map +1 -0
  156. package/dist/test/uniontypeexpression.test.js +152 -15
  157. package/dist/test/uniontypeexpression.test.js.map +1 -1
  158. package/dist/test/variables.test.js +28 -19
  159. package/dist/test/variables.test.js.map +1 -1
  160. package/dist/tsconfig.tsbuildinfo +1 -1
  161. package/package.json +2 -2
  162. package/src/builtins/python.ts +7 -0
  163. package/src/components/CallSignature.tsx +17 -69
  164. package/src/components/ClassMethodDeclaration.tsx +34 -0
  165. package/src/components/ConstructorDeclaration.tsx +37 -0
  166. package/src/components/DunderMethodDeclaration.tsx +30 -0
  167. package/src/components/EnumDeclaration.tsx +16 -44
  168. package/src/components/EnumMember.tsx +3 -3
  169. package/src/components/FunctionBase.tsx +88 -0
  170. package/src/components/FunctionDeclaration.tsx +18 -82
  171. package/src/components/MemberExpression.tsx +6 -19
  172. package/src/components/MethodBase.tsx +53 -0
  173. package/src/components/MethodDeclaration.tsx +27 -0
  174. package/src/components/PropertyDeclaration.tsx +264 -0
  175. package/src/components/PyDoc.tsx +795 -195
  176. package/src/components/SourceFile.tsx +29 -0
  177. package/src/components/StaticMethodDeclaration.tsx +34 -0
  178. package/src/components/TypeArguments.tsx +24 -0
  179. package/src/components/TypeReference.tsx +33 -0
  180. package/src/components/UnionTypeExpression.tsx +4 -15
  181. package/src/components/VariableDeclaration.tsx +1 -3
  182. package/src/components/index.ts +10 -0
  183. package/src/parameter-descriptor.ts +6 -5
  184. package/src/symbol-creation.ts +17 -0
  185. package/src/symbols/factories.ts +39 -0
  186. package/src/symbols/index.ts +1 -0
  187. package/src/symbols/reference.tsx +3 -5
  188. package/src/utils.ts +0 -2
  189. package/temp/api.json +5281 -2273
  190. package/test/callsignatures.test.tsx +102 -74
  191. package/test/class-method-declaration.test.tsx +53 -0
  192. package/test/classdeclarations.test.tsx +7 -9
  193. package/test/constructordeclaration.test.tsx +48 -0
  194. package/test/dundermethoddeclaration.test.tsx +53 -0
  195. package/test/enums.test.tsx +14 -16
  196. package/test/externals.test.tsx +5 -7
  197. package/test/factories.test.tsx +72 -0
  198. package/test/functiondeclaration.test.tsx +196 -44
  199. package/test/memberexpressions.test.tsx +7 -2
  200. package/test/methoddeclaration.test.tsx +202 -0
  201. package/test/namepolicies.test.tsx +1 -2
  202. package/test/propertydeclaration.test.tsx +192 -0
  203. package/test/pydocs.test.tsx +1093 -129
  204. package/test/references.test.tsx +1 -1
  205. package/test/sourcefiles.test.tsx +100 -1
  206. package/test/staticmethoddeclaration.test.tsx +49 -0
  207. package/test/typereference.test.tsx +52 -0
  208. package/test/uniontypeexpression.test.tsx +169 -34
  209. package/test/variables.test.tsx +27 -16
@@ -44,6 +44,10 @@ export interface SourceFileProps {
44
44
  * Comment to add to the header, which will be rendered as a comment in the file.
45
45
  */
46
46
  headerComment?: string;
47
+ /**
48
+ * Documentation for this module, which will be rendered as a module-level docstring.
49
+ */
50
+ doc?: Children;
47
51
  }
48
52
 
49
53
  /**
@@ -62,6 +66,26 @@ export interface SourceFileProps {
62
66
  * def test():
63
67
  * pass
64
68
  * ```
69
+ *
70
+ * @example
71
+ * With module documentation:
72
+ * ```tsx
73
+ * <SourceFile
74
+ * path="utils.py"
75
+ * doc={<ModuleDoc description={[<Prose>Utility functions for data processing.</Prose>]} />}
76
+ * >
77
+ * <FunctionDeclaration name="process_data" />
78
+ * </SourceFile>
79
+ * ```
80
+ * renders to
81
+ * ```py
82
+ * """
83
+ * Utility functions for data processing.
84
+ * """
85
+ *
86
+ * def process_data():
87
+ * pass
88
+ * ```
65
89
  */
66
90
  export function SourceFile(props: SourceFileProps) {
67
91
  const directoryContext = useContext(SourceDirectoryContext)!;
@@ -83,6 +107,11 @@ export function SourceFile(props: SourceFileProps) {
83
107
  <hbr />
84
108
  <hbr />
85
109
  </Show>
110
+ <Show when={props.doc !== undefined}>
111
+ {props.doc}
112
+ <hbr />
113
+ <hbr />
114
+ </Show>
86
115
  <PythonSourceFileContext.Provider value={sfContext}>
87
116
  <Scope value={scope}>
88
117
  <List doubleHardline>{props.children}</List>
@@ -0,0 +1,34 @@
1
+ import { createMethodSymbol } from "../symbols/factories.js";
2
+ import type { CommonFunctionProps } from "./FunctionBase.js";
3
+ import { MethodDeclarationBase } from "./MethodBase.js";
4
+
5
+ /**
6
+ * A Python static method declaration component.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * <py.StaticMethodDeclaration name="identity" parameters={[{ name: "value", type: "int" }]}>
11
+ * return value
12
+ * </py.StaticMethodDeclaration>
13
+ * ```
14
+ * Generates:
15
+ * ```python
16
+ * @staticmethod
17
+ * def identity(value: int) -> None:
18
+ * return value
19
+ * ```
20
+ */
21
+ export interface StaticMethodDeclarationProps extends CommonFunctionProps {
22
+ abstract?: boolean;
23
+ }
24
+
25
+ export function StaticMethodDeclaration(props: StaticMethodDeclarationProps) {
26
+ const sym = createMethodSymbol(props.name, { refkeys: props.refkey });
27
+ return (
28
+ <>
29
+ {"@staticmethod"}
30
+ <hbr />
31
+ <MethodDeclarationBase functionType="static" {...props} sym={sym} />
32
+ </>
33
+ );
34
+ }
@@ -0,0 +1,24 @@
1
+ import { Children, For } from "@alloy-js/core";
2
+
3
+ export interface TypeArgumentsProps {
4
+ args: Children[];
5
+ }
6
+
7
+ /**
8
+ * Render Python-style type arguments, e.g. [T, P].
9
+ */
10
+ export function TypeArguments(props: TypeArgumentsProps) {
11
+ if (!props.args || props.args.length === 0) {
12
+ return undefined;
13
+ }
14
+
15
+ return (
16
+ <>
17
+ [
18
+ <For each={props.args} joiner=", ">
19
+ {(arg) => arg}
20
+ </For>
21
+ ]
22
+ </>
23
+ );
24
+ }
@@ -0,0 +1,33 @@
1
+ import { Children, Refkey, Show } from "@alloy-js/core";
2
+ import { TypeArguments } from "./TypeArguments.js";
3
+
4
+ export interface TypeReferenceProps {
5
+ /** A refkey to a declared symbol. */
6
+ refkey?: Refkey;
7
+ /** A raw name to reference when no refkey is provided. */
8
+ name?: Children;
9
+ /** Type arguments to render inside brackets. */
10
+ typeArgs?: Children[];
11
+ }
12
+
13
+ /**
14
+ * A type reference like Foo[T, P] or int.
15
+ */
16
+ export function TypeReference(props: TypeReferenceProps) {
17
+ const type = props.refkey ? props.refkey : props.name;
18
+ const typeArgs =
19
+ props.typeArgs && props.typeArgs.length ?
20
+ <TypeArguments args={props.typeArgs} />
21
+ : undefined;
22
+
23
+ return (
24
+ <group>
25
+ <indent>
26
+ <sbr />
27
+ {type}
28
+ <Show when={Boolean(typeArgs)}>{typeArgs}</Show>
29
+ </indent>
30
+ <sbr />
31
+ </group>
32
+ );
33
+ }
@@ -1,29 +1,18 @@
1
- import { Children, childrenArray, For, memo } from "@alloy-js/core";
1
+ import { Children, For, childrenArray } from "@alloy-js/core";
2
2
 
3
3
  export interface UnionTypeExpressionProps {
4
- children: Children[];
5
- optional?: boolean;
4
+ children: Children;
6
5
  }
7
6
 
8
7
  export function UnionTypeExpression(props: UnionTypeExpressionProps) {
9
- const resolvedChildren = memo(() => {
10
- const children = childrenArray(() => props.children, {
11
- preserveFragments: true,
12
- });
13
-
14
- if (props.optional) {
15
- children.push("None");
16
- }
17
- return children;
18
- });
19
-
8
+ const items = childrenArray(() => props.children);
20
9
  return (
21
10
  <group>
22
11
  <ifBreak>(</ifBreak>
23
12
  <indent>
24
13
  <sbr />
25
14
  <For
26
- each={resolvedChildren}
15
+ each={items}
27
16
  joiner={
28
17
  <>
29
18
  <br />|{" "}
@@ -4,13 +4,12 @@ import {
4
4
  Name,
5
5
  Show,
6
6
  createSymbolSlot,
7
- emitSymbol,
8
7
  memo,
9
8
  } from "@alloy-js/core";
10
9
  import { createPythonSymbol } from "../symbol-creation.js";
11
10
  import { Atom } from "./Atom.jsx";
12
11
  import { BaseDeclarationProps } from "./Declaration.jsx";
13
- import { SimpleCommentBlock } from "./index.js";
12
+ import { SimpleCommentBlock } from "./PyDoc.jsx";
14
13
 
15
14
  export interface VariableDeclarationProps extends BaseDeclarationProps {
16
15
  /**
@@ -89,7 +88,6 @@ export function VariableDeclaration(props: VariableDeclarationProps) {
89
88
  ValueTypeSymbolSlot.moveMembersTo(sym);
90
89
  }
91
90
 
92
- emitSymbol(sym);
93
91
  // Handle optional type annotation
94
92
  const type = memo(() => {
95
93
  if (!props.type || props.callStatementVar) return undefined;
@@ -2,19 +2,29 @@ export * from "./Atom.js";
2
2
  export * from "./CallSignature.js";
3
3
  export * from "./ClassDeclaration.js";
4
4
  export * from "./ClassInstantiation.js";
5
+ export * from "./ClassMethodDeclaration.js";
6
+ export * from "./ConstructorDeclaration.js";
5
7
  export * from "./Declaration.js";
8
+ export * from "./DunderMethodDeclaration.js";
6
9
  export * from "./EnumDeclaration.js";
7
10
  export * from "./EnumMember.js";
11
+ export type { CommonFunctionProps } from "./FunctionBase.js";
8
12
  export * from "./FunctionCallExpression.js";
9
13
  export * from "./FunctionDeclaration.js";
10
14
  export * from "./ImportStatement.js";
11
15
  export * from "./LexicalScope.js";
12
16
  export * from "./MemberExpression.js";
13
17
  export * from "./MemberScope.jsx";
18
+ export type { MethodDeclarationBaseProps } from "./MethodBase.js";
19
+ export * from "./MethodDeclaration.js";
20
+ export * from "./PropertyDeclaration.js";
14
21
  export * from "./PyDoc.js";
15
22
  export * from "./PythonBlock.js";
16
23
  export * from "./Reference.js";
17
24
  export * from "./SourceFile.js";
18
25
  export * from "./StatementList.js";
26
+ export * from "./StaticMethodDeclaration.js";
27
+ export * from "./TypeArguments.js";
28
+ export * from "./TypeReference.js";
19
29
  export * from "./UnionTypeExpression.js";
20
30
  export * from "./VariableDeclaration.js";
@@ -19,11 +19,6 @@ export interface ParameterDescriptor {
19
19
  */
20
20
  readonly refkey?: Refkey | Refkey[];
21
21
 
22
- /**
23
- * Whether the parameter is optional.
24
- */
25
- readonly optional?: boolean;
26
-
27
22
  /**
28
23
  * Documentation for the parameter.
29
24
  */
@@ -34,3 +29,9 @@ export interface ParameterDescriptor {
34
29
  */
35
30
  readonly default?: Children;
36
31
  }
32
+
33
+ export function isParameterDescriptor(
34
+ param: unknown,
35
+ ): param is ParameterDescriptor {
36
+ return typeof param === "object" && param !== null && "name" in param;
37
+ }
@@ -18,6 +18,22 @@ interface CreatePythonSymbolOptions extends PythonOutputSymbolOptions {
18
18
  space?: OutputSpace;
19
19
  instance?: boolean;
20
20
  }
21
+
22
+ /**
23
+ * Attempts to find an existing symbol by name in the target space.
24
+ */
25
+ export function findExistingSymbol(
26
+ name: string,
27
+ targetSpace?: OutputSpace,
28
+ ): PythonOutputSymbol | undefined {
29
+ if (!targetSpace) {
30
+ return undefined;
31
+ }
32
+
33
+ const existingSymbol = targetSpace.symbolNames.get(name);
34
+ return existingSymbol as PythonOutputSymbol | undefined;
35
+ }
36
+
21
37
  /**
22
38
  * Creates a symbol for a python declaration in the current scope.
23
39
  */
@@ -55,6 +71,7 @@ export function createPythonSymbol(
55
71
  metadata: options.metadata,
56
72
  module: sfContext?.module,
57
73
  type: options.type,
74
+ ignoreNameConflict: options.ignoreNameConflict,
58
75
  namePolicy: usePythonNamePolicy().for(kind),
59
76
  });
60
77
  }
@@ -0,0 +1,39 @@
1
+ import { Namekey } from "@alloy-js/core";
2
+ import { createPythonSymbol } from "../symbol-creation.js";
3
+ import type { PythonOutputSymbol } from "./python-output-symbol.js";
4
+ import { usePythonScope } from "./scopes.js";
5
+
6
+ /**
7
+ * Creates a function symbol in the current scope.
8
+ */
9
+ export function createFunctionSymbol(
10
+ name: string | Namekey,
11
+ options: { refkeys?: any } = {},
12
+ ): PythonOutputSymbol {
13
+ return createPythonSymbol(
14
+ name,
15
+ { instance: false, refkeys: options.refkeys },
16
+ "function",
17
+ );
18
+ }
19
+
20
+ /**
21
+ * Creates a method symbol in a class. Validates that the current scope is a member scope.
22
+ */
23
+ export function createMethodSymbol(
24
+ name: string | Namekey,
25
+ options: { refkeys?: any } = {},
26
+ ): PythonOutputSymbol {
27
+ const scope = usePythonScope();
28
+ if (!scope?.isMemberScope) {
29
+ const displayName = typeof name === "string" ? name : name.name;
30
+ throw new Error(
31
+ `Method "${displayName}" must be declared inside a class (member scope)`,
32
+ );
33
+ }
34
+ return createPythonSymbol(
35
+ name,
36
+ { instance: true, refkeys: options.refkeys },
37
+ "function",
38
+ );
39
+ }
@@ -1,3 +1,4 @@
1
+ export * from "./factories.js";
1
2
  export * from "./python-lexical-scope.js";
2
3
  export * from "./python-member-scope.js";
3
4
  export * from "./python-module-scope.js";
@@ -9,11 +9,9 @@ import {
9
9
  } from "@alloy-js/core";
10
10
  import { MemberExpression } from "../components/MemberExpression.jsx";
11
11
  import { PythonSourceFileContext } from "../components/SourceFile.jsx";
12
- import {
13
- PythonModuleScope,
14
- PythonOutputScope,
15
- PythonOutputSymbol,
16
- } from "./index.js";
12
+ import { PythonModuleScope } from "./python-module-scope.js";
13
+ import { PythonOutputSymbol } from "./python-output-symbol.js";
14
+ import { PythonOutputScope } from "./scopes.js";
17
15
 
18
16
  export function ref(
19
17
  refkey: Refkey,
package/src/utils.ts CHANGED
@@ -14,8 +14,6 @@ export function getCallSignatureProps(
14
14
  "typeParameters",
15
15
  "args",
16
16
  "kwargs",
17
- "instanceFunction",
18
- "classFunction",
19
17
  "returnType",
20
18
  ]);
21
19