@alloy-js/python 0.4.0-dev.3 → 0.4.0-dev.6
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/dev/src/builtins/python.js +30 -0
- package/dist/dev/src/builtins/python.js.map +1 -0
- package/dist/dev/src/components/Atom.js +122 -0
- package/dist/dev/src/components/Atom.js.map +1 -0
- package/dist/dev/src/components/CallSignature.js +195 -0
- package/dist/dev/src/components/CallSignature.js.map +1 -0
- package/dist/dev/src/components/ClassDeclaration.js +112 -0
- package/dist/dev/src/components/ClassDeclaration.js.map +1 -0
- package/dist/dev/src/components/ClassInstantiation.js +40 -0
- package/dist/dev/src/components/ClassInstantiation.js.map +1 -0
- package/dist/dev/src/components/ClassMethodDeclaration.js +40 -0
- package/dist/dev/src/components/ClassMethodDeclaration.js.map +1 -0
- package/dist/dev/src/components/ConstructorDeclaration.js +39 -0
- package/dist/dev/src/components/ConstructorDeclaration.js.map +1 -0
- package/dist/dev/src/components/DataclassDeclaration.js +177 -0
- package/dist/dev/src/components/DataclassDeclaration.js.map +1 -0
- package/dist/dev/src/components/Declaration.js +31 -0
- package/dist/dev/src/components/Declaration.js.map +1 -0
- package/dist/dev/src/components/DunderMethodDeclaration.js +33 -0
- package/dist/dev/src/components/DunderMethodDeclaration.js.map +1 -0
- package/dist/dev/src/components/EnumDeclaration.js +259 -0
- package/dist/dev/src/components/EnumDeclaration.js.map +1 -0
- package/dist/dev/src/components/EnumMember.js +95 -0
- package/dist/dev/src/components/EnumMember.js.map +1 -0
- package/dist/dev/src/components/FunctionBase.js +130 -0
- package/dist/dev/src/components/FunctionBase.js.map +1 -0
- package/dist/dev/src/components/FunctionCallExpression.js +53 -0
- package/dist/dev/src/components/FunctionCallExpression.js.map +1 -0
- package/dist/dev/src/components/FunctionDeclaration.js +45 -0
- package/dist/dev/src/components/FunctionDeclaration.js.map +1 -0
- package/dist/dev/src/components/FutureStatement.js +31 -0
- package/dist/dev/src/components/FutureStatement.js.map +1 -0
- package/dist/dev/src/components/ImportStatement.js +167 -0
- package/dist/dev/src/components/ImportStatement.js.map +1 -0
- package/dist/dev/src/components/LexicalScope.js +26 -0
- package/dist/dev/src/components/LexicalScope.js.map +1 -0
- package/dist/dev/src/components/MemberExpression.js +290 -0
- package/dist/dev/src/components/MemberExpression.js.map +1 -0
- package/dist/dev/src/components/MemberScope.js +23 -0
- package/dist/dev/src/components/MemberScope.js.map +1 -0
- package/dist/dev/src/components/MethodBase.js +40 -0
- package/dist/dev/src/components/MethodBase.js.map +1 -0
- package/dist/dev/src/components/MethodDeclaration.js +38 -0
- package/dist/dev/src/components/MethodDeclaration.js.map +1 -0
- package/dist/dev/src/components/PropertyDeclaration.js +287 -0
- package/dist/dev/src/components/PropertyDeclaration.js.map +1 -0
- package/dist/dev/src/components/PyDoc.js +1478 -0
- package/dist/dev/src/components/PyDoc.js.map +1 -0
- package/dist/dev/src/components/PythonBlock.js +35 -0
- package/dist/dev/src/components/PythonBlock.js.map +1 -0
- package/dist/dev/src/components/Reference.js +23 -0
- package/dist/dev/src/components/Reference.js.map +1 -0
- package/dist/dev/src/components/SourceFile.js +385 -0
- package/dist/dev/src/components/SourceFile.js.map +1 -0
- package/dist/dev/src/components/StatementList.js +34 -0
- package/dist/dev/src/components/StatementList.js.map +1 -0
- package/dist/dev/src/components/StaticMethodDeclaration.js +40 -0
- package/dist/dev/src/components/StaticMethodDeclaration.js.map +1 -0
- package/dist/dev/src/components/TypeArguments.js +22 -0
- package/dist/dev/src/components/TypeArguments.js.map +1 -0
- package/dist/dev/src/components/TypeRefContext.js +33 -0
- package/dist/dev/src/components/TypeRefContext.js.map +1 -0
- package/dist/dev/src/components/TypeReference.js +67 -0
- package/dist/dev/src/components/TypeReference.js.map +1 -0
- package/dist/dev/src/components/UnionTypeExpression.js +57 -0
- package/dist/dev/src/components/UnionTypeExpression.js.map +1 -0
- package/dist/dev/src/components/VariableDeclaration.js +150 -0
- package/dist/dev/src/components/VariableDeclaration.js.map +1 -0
- package/dist/dev/src/components/index.js +32 -0
- package/dist/dev/src/components/index.js.map +1 -0
- package/dist/dev/src/context/index.js +2 -0
- package/dist/dev/src/context/index.js.map +1 -0
- package/dist/dev/src/context/type-ref-context.js +17 -0
- package/dist/dev/src/context/type-ref-context.js.map +1 -0
- package/dist/dev/src/create-module.js +64 -0
- package/dist/dev/src/create-module.js.map +1 -0
- package/dist/dev/src/index.js +8 -0
- package/dist/dev/src/index.js.map +1 -0
- package/dist/dev/src/name-conflict-resolver.js +8 -0
- package/dist/dev/src/name-conflict-resolver.js.map +1 -0
- package/dist/dev/src/name-policy.js +48 -0
- package/dist/dev/src/name-policy.js.map +1 -0
- package/dist/dev/src/parameter-descriptor.js +8 -0
- package/dist/dev/src/parameter-descriptor.js.map +1 -0
- package/dist/dev/src/symbol-creation.js +58 -0
- package/dist/dev/src/symbol-creation.js.map +1 -0
- package/dist/dev/src/symbols/factories.js +28 -0
- package/dist/dev/src/symbols/factories.js.map +1 -0
- package/dist/dev/src/symbols/index.js +8 -0
- package/dist/dev/src/symbols/index.js.map +1 -0
- package/dist/dev/src/symbols/python-lexical-scope.js +15 -0
- package/dist/dev/src/symbols/python-lexical-scope.js.map +1 -0
- package/dist/dev/src/symbols/python-member-scope.js +7 -0
- package/dist/dev/src/symbols/python-member-scope.js.map +1 -0
- package/dist/dev/src/symbols/python-module-scope.js +86 -0
- package/dist/dev/src/symbols/python-module-scope.js.map +1 -0
- package/dist/dev/src/symbols/python-output-symbol.js +73 -0
- package/dist/dev/src/symbols/python-output-symbol.js.map +1 -0
- package/dist/dev/src/symbols/reference.js +87 -0
- package/dist/dev/src/symbols/reference.js.map +1 -0
- package/dist/dev/src/symbols/scopes.js +13 -0
- package/dist/dev/src/symbols/scopes.js.map +1 -0
- package/dist/dev/src/utils.js +13 -0
- package/dist/dev/src/utils.js.map +1 -0
- package/dist/dev/test/callsignatures.test.js +482 -0
- package/dist/dev/test/callsignatures.test.js.map +1 -0
- package/dist/dev/test/class-method-declaration.test.js +85 -0
- package/dist/dev/test/class-method-declaration.test.js.map +1 -0
- package/dist/dev/test/classdeclarations.test.js +654 -0
- package/dist/dev/test/classdeclarations.test.js.map +1 -0
- package/dist/dev/test/classinstantiations.test.js +281 -0
- package/dist/dev/test/classinstantiations.test.js.map +1 -0
- package/dist/dev/test/constructordeclaration.test.js +86 -0
- package/dist/dev/test/constructordeclaration.test.js.map +1 -0
- package/dist/dev/test/dataclassdeclarations.test.js +1068 -0
- package/dist/dev/test/dataclassdeclarations.test.js.map +1 -0
- package/dist/dev/test/dundermethoddeclaration.test.js +93 -0
- package/dist/dev/test/dundermethoddeclaration.test.js.map +1 -0
- package/dist/dev/test/enums.test.js +263 -0
- package/dist/dev/test/enums.test.js.map +1 -0
- package/dist/dev/test/externals.test.js +307 -0
- package/dist/dev/test/externals.test.js.map +1 -0
- package/dist/dev/test/factories.test.js +122 -0
- package/dist/dev/test/factories.test.js.map +1 -0
- package/dist/dev/test/functioncallexpressions.test.js +257 -0
- package/dist/dev/test/functioncallexpressions.test.js.map +1 -0
- package/dist/dev/test/functiondeclaration.test.js +817 -0
- package/dist/dev/test/functiondeclaration.test.js.map +1 -0
- package/dist/dev/test/imports.test.js +372 -0
- package/dist/dev/test/imports.test.js.map +1 -0
- package/dist/dev/test/memberexpressions.test.js +1668 -0
- package/dist/dev/test/memberexpressions.test.js.map +1 -0
- package/dist/dev/test/methoddeclaration.test.js +344 -0
- package/dist/dev/test/methoddeclaration.test.js.map +1 -0
- package/dist/dev/test/namepolicies.test.js +154 -0
- package/dist/dev/test/namepolicies.test.js.map +1 -0
- package/dist/dev/test/propertydeclaration.test.js +354 -0
- package/dist/dev/test/propertydeclaration.test.js.map +1 -0
- package/dist/dev/test/pydocs.test.js +1675 -0
- package/dist/dev/test/pydocs.test.js.map +1 -0
- package/dist/dev/test/references.test.js +66 -0
- package/dist/dev/test/references.test.js.map +1 -0
- package/dist/dev/test/sourcefiles.test.js +1802 -0
- package/dist/dev/test/sourcefiles.test.js.map +1 -0
- package/dist/dev/test/staticmethoddeclaration.test.js +85 -0
- package/dist/dev/test/staticmethoddeclaration.test.js.map +1 -0
- package/dist/dev/test/type-checking-imports.test.js +617 -0
- package/dist/dev/test/type-checking-imports.test.js.map +1 -0
- package/dist/dev/test/typereference.test.js +79 -0
- package/dist/dev/test/typereference.test.js.map +1 -0
- package/dist/dev/test/uniontypeexpression.test.js +307 -0
- package/dist/dev/test/uniontypeexpression.test.js.map +1 -0
- package/dist/dev/test/utils.js +100 -0
- package/dist/dev/test/utils.js.map +1 -0
- package/dist/dev/test/values.test.js +182 -0
- package/dist/dev/test/values.test.js.map +1 -0
- package/dist/dev/test/variables.test.js +363 -0
- package/dist/dev/test/variables.test.js.map +1 -0
- package/dist/src/components/CallSignature.d.ts.map +1 -1
- package/dist/src/components/CallSignature.js +12 -3
- package/dist/src/components/CallSignature.js.map +1 -1
- package/dist/src/components/ImportStatement.d.ts +12 -0
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/ImportStatement.js +45 -3
- package/dist/src/components/ImportStatement.js.map +1 -1
- package/dist/src/components/Reference.d.ts.map +1 -1
- package/dist/src/components/Reference.js +5 -1
- package/dist/src/components/Reference.js.map +1 -1
- package/dist/src/components/SourceFile.d.ts +1 -1
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +46 -7
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/components/TypeRefContext.d.ts +26 -0
- package/dist/src/components/TypeRefContext.d.ts.map +1 -0
- package/dist/src/components/TypeRefContext.js +29 -0
- package/dist/src/components/TypeRefContext.js.map +1 -0
- package/dist/src/components/TypeReference.d.ts +5 -0
- package/dist/src/components/TypeReference.d.ts.map +1 -1
- package/dist/src/components/TypeReference.js +19 -9
- package/dist/src/components/TypeReference.js.map +1 -1
- package/dist/src/components/VariableDeclaration.d.ts.map +1 -1
- package/dist/src/components/VariableDeclaration.js +7 -2
- package/dist/src/components/VariableDeclaration.js.map +1 -1
- package/dist/src/components/index.d.ts +1 -1
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +1 -1
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/context/index.d.ts +2 -0
- package/dist/src/context/index.d.ts.map +1 -0
- package/dist/src/context/index.js +2 -0
- package/dist/src/context/index.js.map +1 -0
- package/dist/src/context/type-ref-context.d.ts +13 -0
- package/dist/src/context/type-ref-context.d.ts.map +1 -0
- package/dist/src/context/type-ref-context.js +17 -0
- package/dist/src/context/type-ref-context.js.map +1 -0
- package/dist/src/name-conflict-resolver.d.ts +2 -2
- package/dist/src/name-conflict-resolver.d.ts.map +1 -1
- package/dist/src/name-conflict-resolver.js +2 -2
- package/dist/src/name-conflict-resolver.js.map +1 -1
- package/dist/src/symbols/python-module-scope.d.ts +13 -1
- package/dist/src/symbols/python-module-scope.d.ts.map +1 -1
- package/dist/src/symbols/python-module-scope.js +36 -2
- package/dist/src/symbols/python-module-scope.js.map +1 -1
- package/dist/src/symbols/python-output-symbol.d.ts +11 -0
- package/dist/src/symbols/python-output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/python-output-symbol.js +26 -2
- package/dist/src/symbols/python-output-symbol.js.map +1 -1
- package/dist/src/symbols/reference.d.ts +8 -1
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +4 -2
- package/dist/src/symbols/reference.js.map +1 -1
- package/dist/test/dataclassdeclarations.test.js +5 -2
- package/dist/test/dataclassdeclarations.test.js.map +1 -1
- package/dist/test/externals.test.js +8 -2
- package/dist/test/externals.test.js.map +1 -1
- package/dist/test/functiondeclaration.test.js +6 -3
- package/dist/test/functiondeclaration.test.js.map +1 -1
- package/dist/test/imports.test.js +3 -3
- package/dist/test/imports.test.js.map +1 -1
- package/dist/test/references.test.js +1 -1
- package/dist/test/references.test.js.map +1 -1
- package/dist/test/sourcefiles.test.js +26 -26
- package/dist/test/sourcefiles.test.js.map +1 -1
- package/dist/test/type-checking-imports.test.d.ts +2 -0
- package/dist/test/type-checking-imports.test.d.ts.map +1 -0
- package/dist/test/type-checking-imports.test.js +437 -0
- package/dist/test/type-checking-imports.test.js.map +1 -0
- package/dist/test/uniontypeexpression.test.js +4 -1
- package/dist/test/uniontypeexpression.test.js.map +1 -1
- package/dist/test/variables.test.js +4 -1
- package/dist/test/variables.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/docs/api/components/AttributeDoc.md +36 -0
- package/docs/api/components/CallSignature.md +62 -0
- package/docs/api/components/CallSignatureParameters.md +49 -0
- package/docs/api/components/ClassDeclaration.md +67 -0
- package/docs/api/components/ClassDoc.md +55 -0
- package/docs/api/components/ClassEnumDeclaration.md +111 -0
- package/docs/api/components/ClassInstantiation.md +44 -0
- package/docs/api/components/ClassMethodDeclaration.md +31 -0
- package/docs/api/components/ConstructorDeclaration.md +27 -0
- package/docs/api/components/DataclassDeclaration.md +55 -0
- package/docs/api/components/Declaration.md +41 -0
- package/docs/api/components/DunderMethodDeclaration.md +31 -0
- package/docs/api/components/EnumMember.md +61 -0
- package/docs/api/components/ExceptionDoc.md +55 -0
- package/docs/api/components/FunctionCallExpression.md +43 -0
- package/docs/api/components/FunctionDeclaration.md +50 -0
- package/docs/api/components/FunctionDoc.md +61 -0
- package/docs/api/components/FunctionalEnumDeclaration.md +79 -0
- package/docs/api/components/FutureStatement.md +51 -0
- package/docs/api/components/GeneratorDoc.md +58 -0
- package/docs/api/components/InlineDoc.md +29 -0
- package/docs/api/components/LexicalScope.md +65 -0
- package/docs/api/components/MemberExpression.md +53 -0
- package/docs/api/components/MemberScope.md +28 -0
- package/docs/api/components/MethodDeclaration.md +49 -0
- package/docs/api/components/MethodDoc.md +61 -0
- package/docs/api/components/ModuleDoc.md +52 -0
- package/docs/api/components/PropertyDeclaration.md +46 -0
- package/docs/api/components/PropertyDoc.md +52 -0
- package/docs/api/components/PyDoc.md +29 -0
- package/docs/api/components/PyDocExample.md +29 -0
- package/docs/api/components/PythonBlock.md +47 -0
- package/docs/api/components/Reference.md +31 -0
- package/docs/api/components/SimpleCommentBlock.md +27 -0
- package/docs/api/components/SimpleInlineComment.md +27 -0
- package/docs/api/components/SourceFile.md +83 -0
- package/docs/api/components/StatementList.md +47 -0
- package/docs/api/components/StaticMethodDeclaration.md +31 -0
- package/docs/api/components/TypeArguments.md +27 -0
- package/docs/api/components/TypeRefContext.md +41 -0
- package/docs/api/components/TypeReference.md +37 -0
- package/docs/api/components/UnionTypeExpression.md +27 -0
- package/docs/api/components/VariableDeclaration.md +87 -0
- package/docs/api/components/index.md +46 -0
- package/docs/api/components/useSourceFile.md +19 -0
- package/docs/api/contexts/PythonSourceFile-context.md +18 -0
- package/docs/api/contexts/index.md +3 -0
- package/docs/api/functions/createFunctionSymbol.md +23 -0
- package/docs/api/functions/createMethodSymbol.md +23 -0
- package/docs/api/functions/createModule.md +18 -0
- package/docs/api/functions/createPythonNamePolicy.md +17 -0
- package/docs/api/functions/getCallSignatureProps.md +21 -0
- package/docs/api/functions/index.md +13 -0
- package/docs/api/functions/isParameterDescriptor.md +18 -0
- package/docs/api/functions/isTypeRefContext.md +17 -0
- package/docs/api/functions/ref.md +25 -0
- package/docs/api/functions/usePythonLexicalScope.md +17 -0
- package/docs/api/functions/usePythonNamePolicy.md +17 -0
- package/docs/api/functions/usePythonScope.md +17 -0
- package/docs/api/index.md +7 -0
- package/docs/api/types/AddImportOptions.md +7 -0
- package/docs/api/types/BaseDeclarationProps.md +10 -0
- package/docs/api/types/CommonFunctionProps.md +15 -0
- package/docs/api/types/CreateModuleProps.md +8 -0
- package/docs/api/types/CreatePythonSymbolFunctionOptions.md +9 -0
- package/docs/api/types/DataclassDecoratorKey.md +5 -0
- package/docs/api/types/DataclassDecoratorKwargs.md +5 -0
- package/docs/api/types/EnumPropsBase.md +11 -0
- package/docs/api/types/GoogleStyleDocAttributeProps.md +9 -0
- package/docs/api/types/ImportRecordProps.md +7 -0
- package/docs/api/types/ImportRecords.md +8 -0
- package/docs/api/types/ImportedSymbol.md +10 -0
- package/docs/api/types/LexicalScopeProps.md +5 -0
- package/docs/api/types/MemberExpressionPartProps.md +13 -0
- package/docs/api/types/ModuleDescriptor.md +7 -0
- package/docs/api/types/ModuleRefkeys.md +7 -0
- package/docs/api/types/NamedMap.md +7 -0
- package/docs/api/types/ParameterDescriptor.md +13 -0
- package/docs/api/types/ParameterMarker.md +5 -0
- package/docs/api/types/PropertyMethodDeclarationProps.md +9 -0
- package/docs/api/types/PythonElements.md +5 -0
- package/docs/api/types/PythonLexicalScope.md +11 -0
- package/docs/api/types/PythonMemberScope.md +9 -0
- package/docs/api/types/PythonModuleScope.md +13 -0
- package/docs/api/types/PythonOutputScope.md +5 -0
- package/docs/api/types/PythonOutputSymbol.md +21 -0
- package/docs/api/types/PythonOutputSymbolOptions.md +10 -0
- package/docs/api/types/RefOptions.md +7 -0
- package/docs/api/types/SubscriptionProps.md +9 -0
- package/docs/api/types/index.md +31 -0
- package/docs/api/variables/abcModule.md +7 -0
- package/docs/api/variables/dataclassDecoratorKeySet.md +5 -0
- package/docs/api/variables/dataclassDecoratorKeys.md +7 -0
- package/docs/api/variables/dataclassesModule.md +7 -0
- package/docs/api/variables/enumModule.md +7 -0
- package/docs/api/variables/index.md +8 -0
- package/docs/api/variables/requestsModule.md +8 -0
- package/package.json +7 -5
- package/src/components/CallSignature.tsx +6 -2
- package/src/components/ImportStatement.tsx +51 -4
- package/src/components/Reference.tsx +3 -1
- package/src/components/SourceFile.tsx +44 -8
- package/src/components/TypeRefContext.tsx +36 -0
- package/src/components/TypeReference.tsx +15 -7
- package/src/components/VariableDeclaration.tsx +5 -1
- package/src/components/index.ts +1 -1
- package/src/context/index.ts +1 -0
- package/src/context/type-ref-context.tsx +16 -0
- package/src/name-conflict-resolver.ts +4 -10
- package/src/symbols/python-module-scope.ts +55 -2
- package/src/symbols/python-output-symbol.ts +32 -1
- package/src/symbols/reference.tsx +10 -0
- package/temp/api.json +441 -336
- package/test/dataclassdeclarations.test.tsx +8 -2
- package/test/externals.test.tsx +8 -2
- package/test/functiondeclaration.test.tsx +6 -3
- package/test/imports.test.tsx +6 -6
- package/test/references.test.tsx +1 -1
- package/test/sourcefiles.test.tsx +13 -13
- package/test/type-checking-imports.test.tsx +363 -0
- package/test/uniontypeexpression.test.tsx +4 -1
- package/test/variables.test.tsx +4 -1
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# PythonLexicalScope
|
|
2
|
+
|
|
3
|
+
## Members
|
|
4
|
+
|
|
5
|
+
Extends [OutputScope](../../../core/types/outputscope/)
|
|
6
|
+
|
|
7
|
+
| | | |
|
|
8
|
+
| ----------------- | ------------------------------------------------------------------------ | - |
|
|
9
|
+
| declarationSpaces | readonly string\[] | |
|
|
10
|
+
| ownerSymbol | undefined | |
|
|
11
|
+
| symbols | import(“@alloy-js/core”).[OutputSpace](../../../core/types/outputspace/) | |
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# PythonModuleScope
|
|
2
|
+
|
|
3
|
+
## Members
|
|
4
|
+
|
|
5
|
+
Extends [PythonLexicalScope](../pythonlexicalscope/)
|
|
6
|
+
|
|
7
|
+
| | | |
|
|
8
|
+
| --------------- | -------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
9
|
+
| addImport | (targetSymbol: PythonOutputSymbol, targetModule: PythonModuleScope, options: AddImportOptions) => PythonOutputSymbol | |
|
|
10
|
+
| addTypeImport | () => PythonOutputSymbol | Add TYPE\_CHECKING import from the typing module. Returns the local symbol for use in the if block opener. |
|
|
11
|
+
| debugInfo | Record\<string, unknown> | |
|
|
12
|
+
| importedModules | [ImportRecords](../importrecords/) | |
|
|
13
|
+
| importedSymbols | Map<[PythonOutputSymbol](../pythonoutputsymbol/), [PythonOutputSymbol](../pythonoutputsymbol/)> | |
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# PythonOutputSymbol
|
|
2
|
+
|
|
3
|
+
Represents an ‘exported’ symbol from a .py file. Class, enum, interface etc.
|
|
4
|
+
|
|
5
|
+
## Members
|
|
6
|
+
|
|
7
|
+
Extends [OutputSymbol](../../../core/types/outputsymbol/)
|
|
8
|
+
|
|
9
|
+
| | | |
|
|
10
|
+
| ---------------------- | ----------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
|
|
11
|
+
| constructor | (name: string \| Namekey, spaces: OutputSpace\[] \| OutputSpace \| undefined, options: PythonOutputSymbolOptions) | Constructs a new instance of the [`PythonOutputSymbol`](PythonOutputSymbol.md) class |
|
|
12
|
+
| copy | () => PythonOutputSymbol | |
|
|
13
|
+
| debugInfo | Record\<string, unknown> | |
|
|
14
|
+
| instanceMembers | import(“@alloy-js/core”).[OutputMemberSpace](../../../core/types/outputmemberspace/) | |
|
|
15
|
+
| isInstanceMemberSymbol | boolean | |
|
|
16
|
+
| isStaticMemberSymbol | boolean | |
|
|
17
|
+
| isTypeOnly | boolean | Returns true if this symbol is only used in type annotation contexts. Such symbols can be imported inside a TYPE\_CHECKING block. |
|
|
18
|
+
| markAsValue | () => void | Mark this symbol as also being used as a value (not just a type). |
|
|
19
|
+
| memberSpaces | readonly \[“static”, “instance”] | |
|
|
20
|
+
| module | string \| undefined | |
|
|
21
|
+
| staticMembers | import(“@alloy-js/core”).[OutputMemberSpace](../../../core/types/outputmemberspace/) | |
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# PythonOutputSymbolOptions
|
|
2
|
+
|
|
3
|
+
## Members
|
|
4
|
+
|
|
5
|
+
Extends [OutputSymbolOptions](../../../core/types/outputsymboloptions/)
|
|
6
|
+
|
|
7
|
+
| | | |
|
|
8
|
+
| -------- | ---------------- | ------------------------------------------------------------ |
|
|
9
|
+
| module | optional string | |
|
|
10
|
+
| typeOnly | optional boolean | Whether this symbol is only used in type annotation contexts |
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# RefOptions
|
|
2
|
+
|
|
3
|
+
## Members
|
|
4
|
+
|
|
5
|
+
| | | |
|
|
6
|
+
| ---- | ---------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
|
7
|
+
| type | optional boolean | If true, this reference is only used in a type annotation context. The import will be guarded with `if TYPE_CHECKING:`. |
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# SubscriptionProps
|
|
2
|
+
|
|
3
|
+
## Members
|
|
4
|
+
|
|
5
|
+
| | | |
|
|
6
|
+
| ----- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
7
|
+
| key | optional [Children](../../../core/types/children/) | Single key for subscription access (obj\[key] or obj\[0]). Use this for single subscription access. |
|
|
8
|
+
| keys | optional [Children](../../../core/types/children/)\[] | Multiple keys for tuple subscription access (obj\[a, b] -> obj\[(a, b)]). Use this when you need tuple key access. |
|
|
9
|
+
| slice | optional { start?: [Children](../../../core/types/children/); stop?: [Children](../../../core/types/children/); step?: [Children](../../../core/types/children/); } | Slice notation for subscription access (obj\[start:stop:step]). Use this for Python slice syntax. |
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# python — types
|
|
2
|
+
|
|
3
|
+
- [AddImportOptions](AddImportOptions.md)
|
|
4
|
+
- [BaseDeclarationProps](BaseDeclarationProps.md)
|
|
5
|
+
- [CommonFunctionProps](CommonFunctionProps.md) — Shared base interface for function-like components.
|
|
6
|
+
- [CreateModuleProps](CreateModuleProps.md)
|
|
7
|
+
- [CreatePythonSymbolFunctionOptions](CreatePythonSymbolFunctionOptions.md) — Extends [PythonOutputSymbolOptions](../pythonoutputsymboloptions/)
|
|
8
|
+
- [DataclassDecoratorKey](DataclassDecoratorKey.md) — type DataclassDecoratorKey = (typeof dataclassDecoratorKeys)[number];
|
|
9
|
+
- [DataclassDecoratorKwargs](DataclassDecoratorKwargs.md) — type DataclassDecoratorKwargs = Partial<Record<DataclassDecoratorKey, boolean>>;
|
|
10
|
+
- [EnumPropsBase](EnumPropsBase.md) — Extends [BaseDeclarationProps](../basedeclarationprops/)
|
|
11
|
+
- [GoogleStyleDocAttributeProps](GoogleStyleDocAttributeProps.md)
|
|
12
|
+
- [ImportedSymbol](ImportedSymbol.md)
|
|
13
|
+
- [ImportRecordProps](ImportRecordProps.md)
|
|
14
|
+
- [ImportRecords](ImportRecords.md) — Extends Map<[PythonModuleScope](../pythonmodulescope/), [ImportRecordProps](../importrecordprops/)>
|
|
15
|
+
- [LexicalScopeProps](LexicalScopeProps.md) — type LexicalScopeProps = LexicalScopePropsWithScopeValue | LeixcalScopePropsWithScopeInfo;
|
|
16
|
+
- [MemberExpressionPartProps](MemberExpressionPartProps.md)
|
|
17
|
+
- [ModuleDescriptor](ModuleDescriptor.md)
|
|
18
|
+
- [ModuleRefkeys](ModuleRefkeys.md) — type ModuleRefkeys<PD extends Record<string, string[]>> = {
|
|
19
|
+
- [NamedMap](NamedMap.md) — type NamedMap<TDescriptor extends readonly string[]> = {
|
|
20
|
+
- [ParameterDescriptor](ParameterDescriptor.md) — Information for a Python function parameter.
|
|
21
|
+
- [ParameterMarker](ParameterMarker.md) — type ParameterMarker = "*" | "/";
|
|
22
|
+
- [PropertyMethodDeclarationProps](PropertyMethodDeclarationProps.md) — Extends Omit<[CommonFunctionProps](../commonfunctionprops/), “name”>
|
|
23
|
+
- [PythonElements](PythonElements.md) — type PythonElements = "class" | "class-member" | "function" | "variable" | "object-member" | "constant" | "parameter" |
|
|
24
|
+
- [PythonLexicalScope](PythonLexicalScope.md) — Extends [OutputScope](../../../core/types/outputscope/)
|
|
25
|
+
- [PythonMemberScope](PythonMemberScope.md) — Extends [OutputScope](../../../core/types/outputscope/)
|
|
26
|
+
- [PythonModuleScope](PythonModuleScope.md) — Extends [PythonLexicalScope](../pythonlexicalscope/)
|
|
27
|
+
- [PythonOutputScope](PythonOutputScope.md) — type PythonOutputScope = PythonLexicalScope | PythonModuleScope | PythonMemberScope;
|
|
28
|
+
- [PythonOutputSymbol](PythonOutputSymbol.md) — Represents an ‘exported’ symbol from a .py file.
|
|
29
|
+
- [PythonOutputSymbolOptions](PythonOutputSymbolOptions.md) — Extends [OutputSymbolOptions](../../../core/types/outputsymboloptions/)
|
|
30
|
+
- [RefOptions](RefOptions.md)
|
|
31
|
+
- [SubscriptionProps](SubscriptionProps.md)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# dataclassDecoratorKeys
|
|
2
|
+
|
|
3
|
+
Allowed keyword arguments for the Python `@dataclass(...)` decorator. Single source of truth: runtime keys and compile-time type are derived here.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
dataclassDecoratorKeys: readonly ["init", "repr", "eq", "order", "unsafeHash", "frozen", "matchArgs", "kwOnly", "slots", "weakrefSlot"]
|
|
7
|
+
```
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# python — variables
|
|
2
|
+
|
|
3
|
+
- [abcModule](abcModule.md) — abcModule: import("../create-module.js").ModuleRefkeys<{
|
|
4
|
+
- [dataclassDecoratorKeys](dataclassDecoratorKeys.md) — Allowed keyword arguments for the Python `@dataclass(...)` decorator.
|
|
5
|
+
- [dataclassDecoratorKeySet](dataclassDecoratorKeySet.md) — dataclassDecoratorKeySet: Set<string>
|
|
6
|
+
- [dataclassesModule](dataclassesModule.md) — dataclassesModule: import("../create-module.js").ModuleRefkeys<{
|
|
7
|
+
- [enumModule](enumModule.md) — enumModule: import("../create-module.js").ModuleRefkeys<{
|
|
8
|
+
- [requestsModule](requestsModule.md) — requestsModule: import("../create-module.js").ModuleRefkeys<{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alloy-js/python",
|
|
3
|
-
"version": "0.4.0-dev.
|
|
3
|
+
"version": "0.4.0-dev.6",
|
|
4
4
|
"description": "Python bindings for Alloy",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,9 +8,11 @@
|
|
|
8
8
|
},
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
+
"development": "./dist/dev/src/index.js",
|
|
11
12
|
"import": "./dist/src/index.js"
|
|
12
13
|
},
|
|
13
14
|
"./stc": {
|
|
15
|
+
"development": "./dist/dev/src/components/stc/index.js",
|
|
14
16
|
"import": "./dist/src/components/stc/index.js"
|
|
15
17
|
}
|
|
16
18
|
},
|
|
@@ -18,13 +20,13 @@
|
|
|
18
20
|
"author": "",
|
|
19
21
|
"license": "MIT",
|
|
20
22
|
"dependencies": {
|
|
21
|
-
"@alloy-js/core": "~0.22.0 || >= 0.23.0-dev.
|
|
23
|
+
"@alloy-js/core": "~0.22.0 || >= 0.23.0-dev.15",
|
|
22
24
|
"change-case": "^5.4.4",
|
|
23
25
|
"pathe": "^2.0.3"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
|
-
"@alloy-js/cli": "~0.22.0 || >= 0.23.0-dev.
|
|
27
|
-
"@alloy-js/rollup-plugin": "~0.1.0 || >= 0.1.1-dev.
|
|
28
|
+
"@alloy-js/cli": "~0.22.0 || >= 0.23.0-dev.5",
|
|
29
|
+
"@alloy-js/rollup-plugin": "~0.1.0 || >= 0.1.1-dev.2",
|
|
28
30
|
"@microsoft/api-extractor": "~7.52.8",
|
|
29
31
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
30
32
|
"concurrently": "^9.2.0",
|
|
@@ -34,7 +36,7 @@
|
|
|
34
36
|
"type": "module",
|
|
35
37
|
"scripts": {
|
|
36
38
|
"generate-docs": "api-extractor run",
|
|
37
|
-
"build": "alloy build && pnpm run generate-docs",
|
|
39
|
+
"build": "alloy build --with-dev && pnpm run generate-docs",
|
|
38
40
|
"clean": "rimraf dist/ .temp/",
|
|
39
41
|
"test:watch": "vitest -w",
|
|
40
42
|
"watch": "alloy build --watch",
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
import { createPythonSymbol } from "../symbol-creation.js";
|
|
14
14
|
import { PythonOutputSymbol } from "../symbols/index.js";
|
|
15
15
|
import { Atom } from "./Atom.jsx";
|
|
16
|
+
import { TypeRefContext } from "./TypeRefContext.jsx";
|
|
16
17
|
|
|
17
18
|
export type ParameterMarker = "*" | "/";
|
|
18
19
|
|
|
@@ -75,7 +76,10 @@ function parameter(param: DeclaredParameterDescriptor) {
|
|
|
75
76
|
<group>
|
|
76
77
|
{param.symbol.name}
|
|
77
78
|
<Show when={!!param.type}>
|
|
78
|
-
:
|
|
79
|
+
:{" "}
|
|
80
|
+
<TypeRefContext>
|
|
81
|
+
<TypeSlot>{param.type}</TypeSlot>
|
|
82
|
+
</TypeRefContext>
|
|
79
83
|
</Show>
|
|
80
84
|
<Show when={param.default !== undefined}>
|
|
81
85
|
<Show when={!param.type}>=</Show>
|
|
@@ -184,7 +188,7 @@ export function CallSignature(props: CallSignatureProps) {
|
|
|
184
188
|
props.returnType ?
|
|
185
189
|
<>
|
|
186
190
|
{" -> "}
|
|
187
|
-
{props.returnType}
|
|
191
|
+
<TypeRefContext>{props.returnType}</TypeRefContext>
|
|
188
192
|
</>
|
|
189
193
|
: undefined;
|
|
190
194
|
|
|
@@ -6,6 +6,53 @@ export interface ImportStatementsProps {
|
|
|
6
6
|
joinImportsFromSameModule?: boolean;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
export interface CategorizedImports {
|
|
10
|
+
/** Imports used only in type annotation contexts (for TYPE_CHECKING block) */
|
|
11
|
+
typeImports: ImportRecords;
|
|
12
|
+
/** Regular imports used at runtime */
|
|
13
|
+
valueImports: ImportRecords;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Categorize import records into type-only and value imports.
|
|
18
|
+
* Type-only imports are those used only in type annotation contexts.
|
|
19
|
+
* Value imports are regular imports used at runtime.
|
|
20
|
+
*/
|
|
21
|
+
export function categorizeImportRecords(
|
|
22
|
+
records: ImportRecords,
|
|
23
|
+
): CategorizedImports {
|
|
24
|
+
const typeImports = new Map() as ImportRecords;
|
|
25
|
+
const valueImports = new Map() as ImportRecords;
|
|
26
|
+
|
|
27
|
+
for (const [module, properties] of records) {
|
|
28
|
+
if (!properties.symbols || properties.symbols.size === 0) {
|
|
29
|
+
// Module-level imports without symbols go to value imports
|
|
30
|
+
valueImports.set(module, properties);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const typeSymbols = new Set<ImportedSymbol>();
|
|
35
|
+
const valueSymbols = new Set<ImportedSymbol>();
|
|
36
|
+
|
|
37
|
+
for (const sym of properties.symbols) {
|
|
38
|
+
if (sym.local.isTypeOnly) {
|
|
39
|
+
typeSymbols.add(sym);
|
|
40
|
+
} else {
|
|
41
|
+
valueSymbols.add(sym);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (typeSymbols.size > 0) {
|
|
46
|
+
typeImports.set(module, { symbols: typeSymbols });
|
|
47
|
+
}
|
|
48
|
+
if (valueSymbols.size > 0) {
|
|
49
|
+
valueImports.set(module, { symbols: valueSymbols });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return { typeImports, valueImports };
|
|
54
|
+
}
|
|
55
|
+
|
|
9
56
|
/**
|
|
10
57
|
* A component that renders import statements based on the provided import records.
|
|
11
58
|
*
|
|
@@ -16,11 +63,11 @@ export interface ImportStatementsProps {
|
|
|
16
63
|
*/
|
|
17
64
|
export function ImportStatements(props: ImportStatementsProps) {
|
|
18
65
|
// Sort the import records by module name
|
|
19
|
-
const imports = computed(() =>
|
|
20
|
-
[...props.records].sort(([a], [b]) => {
|
|
66
|
+
const imports = computed(() => {
|
|
67
|
+
return [...props.records].sort(([a], [b]) => {
|
|
21
68
|
return a.name.localeCompare(b.name);
|
|
22
|
-
})
|
|
23
|
-
);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
24
71
|
|
|
25
72
|
return mapJoin(
|
|
26
73
|
() => imports.value,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { computed, emitSymbol, Refkey } from "@alloy-js/core";
|
|
2
|
+
import { isTypeRefContext } from "../context/type-ref-context.js";
|
|
2
3
|
import { ref } from "../symbols/index.js";
|
|
3
4
|
|
|
4
5
|
export interface ReferenceProps {
|
|
@@ -13,7 +14,8 @@ export interface ReferenceProps {
|
|
|
13
14
|
* It takes a `refkey` prop which is the key of the symbol to reference.
|
|
14
15
|
*/
|
|
15
16
|
export function Reference({ refkey }: ReferenceProps) {
|
|
16
|
-
const
|
|
17
|
+
const inTypeRef = isTypeRefContext();
|
|
18
|
+
const reference = ref(refkey, { type: inTypeRef });
|
|
17
19
|
const symbolRef = computed(() => reference()[1]);
|
|
18
20
|
|
|
19
21
|
emitSymbol(symbolRef);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
childrenArray,
|
|
3
3
|
ComponentContext,
|
|
4
|
+
computed,
|
|
4
5
|
SourceFile as CoreSourceFile,
|
|
5
6
|
createNamedContext,
|
|
6
7
|
createScope,
|
|
@@ -14,8 +15,12 @@ import {
|
|
|
14
15
|
} from "@alloy-js/core";
|
|
15
16
|
import { join } from "pathe";
|
|
16
17
|
import { PythonModuleScope } from "../symbols/index.js";
|
|
17
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
categorizeImportRecords,
|
|
20
|
+
ImportStatements,
|
|
21
|
+
} from "./ImportStatement.js";
|
|
18
22
|
import { SimpleCommentBlock } from "./PyDoc.js";
|
|
23
|
+
import { PythonBlock } from "./PythonBlock.js";
|
|
19
24
|
import { Reference } from "./Reference.js";
|
|
20
25
|
|
|
21
26
|
// Non top-level definitions
|
|
@@ -99,7 +104,7 @@ export interface SourceFileProps {
|
|
|
99
104
|
/**
|
|
100
105
|
* __future__ imports to render after the docstring but before regular imports.
|
|
101
106
|
*/
|
|
102
|
-
futureImports?: Children;
|
|
107
|
+
futureImports?: Children[];
|
|
103
108
|
}
|
|
104
109
|
|
|
105
110
|
/**
|
|
@@ -167,6 +172,28 @@ export function SourceFile(props: SourceFileProps) {
|
|
|
167
172
|
props.doc !== undefined ||
|
|
168
173
|
props.futureImports !== undefined;
|
|
169
174
|
|
|
175
|
+
const imports = computed(() => {
|
|
176
|
+
// Quick scan for any type-only imports
|
|
177
|
+
const hasTypeImports = [...scope.importedModules.values()].some(
|
|
178
|
+
(props) =>
|
|
179
|
+
props.symbols && [...props.symbols].some((s) => s.local.isTypeOnly),
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
// Add TYPE_CHECKING before categorizing so it's naturally included
|
|
183
|
+
const typeImportSymbol = hasTypeImports ? scope.addTypeImport() : undefined;
|
|
184
|
+
|
|
185
|
+
// Single categorize - TYPE_CHECKING is already in scope.importedModules
|
|
186
|
+
const { valueImports, typeImports } = categorizeImportRecords(
|
|
187
|
+
scope.importedModules,
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
return {
|
|
191
|
+
valueImports,
|
|
192
|
+
typeImports,
|
|
193
|
+
typeImportSymbol,
|
|
194
|
+
};
|
|
195
|
+
});
|
|
196
|
+
|
|
170
197
|
return (
|
|
171
198
|
<CoreSourceFile
|
|
172
199
|
path={props.path}
|
|
@@ -216,12 +243,21 @@ export function SourceFile(props: SourceFileProps) {
|
|
|
216
243
|
<hbr />
|
|
217
244
|
</Show>
|
|
218
245
|
</Show>
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
<
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
246
|
+
{/* Regular (non-type-only) imports */}
|
|
247
|
+
<Show when={imports.value.valueImports.size > 0}>
|
|
248
|
+
<ImportStatements records={imports.value.valueImports} />
|
|
249
|
+
<hbr />
|
|
250
|
+
</Show>
|
|
251
|
+
{/* TYPE_CHECKING block with type-only imports */}
|
|
252
|
+
<Show when={imports.value.typeImports.size > 0}>
|
|
253
|
+
<hbr />
|
|
254
|
+
<PythonBlock opener={`if ${imports.value.typeImportSymbol!.name}:`}>
|
|
255
|
+
<ImportStatements records={imports.value.typeImports} />
|
|
256
|
+
</PythonBlock>
|
|
257
|
+
</Show>
|
|
258
|
+
{/* Spacing after imports */}
|
|
259
|
+
<Show when={hasChildren && scope.importedModules.size > 0}>
|
|
260
|
+
<hbr />
|
|
225
261
|
</Show>
|
|
226
262
|
{/* Extra blank line before top-level definitions */}
|
|
227
263
|
<Show
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Children } from "@alloy-js/core";
|
|
2
|
+
import {
|
|
3
|
+
isTypeRefContext,
|
|
4
|
+
TypeRefContextDef,
|
|
5
|
+
} from "../context/type-ref-context.js";
|
|
6
|
+
|
|
7
|
+
// Re-export for external use
|
|
8
|
+
export { isTypeRefContext };
|
|
9
|
+
|
|
10
|
+
export interface TypeRefContextProps {
|
|
11
|
+
/**
|
|
12
|
+
* Children
|
|
13
|
+
*/
|
|
14
|
+
children: Children;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Set the current context of reference to be type reference.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* References used inside the children of this component will be treated as
|
|
22
|
+
* type-only references. When a symbol is only referenced in type contexts,
|
|
23
|
+
* it will be imported inside a `if TYPE_CHECKING:` block.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* <TypeRefContext>
|
|
28
|
+
* {someTypeRefkey}
|
|
29
|
+
* </TypeRefContext>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export const TypeRefContext = ({ children }: TypeRefContextProps) => {
|
|
33
|
+
return (
|
|
34
|
+
<TypeRefContextDef.Provider value>{children}</TypeRefContextDef.Provider>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Children, Refkey, Show } from "@alloy-js/core";
|
|
2
2
|
import { TypeArguments } from "./TypeArguments.js";
|
|
3
|
+
import { TypeRefContext } from "./TypeRefContext.js";
|
|
3
4
|
|
|
4
5
|
export interface TypeReferenceProps {
|
|
5
6
|
/** A refkey to a declared symbol. */
|
|
@@ -12,6 +13,11 @@ export interface TypeReferenceProps {
|
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* A type reference like Foo[T, P] or int.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* This component automatically wraps its content in a type reference context,
|
|
19
|
+
* so any symbols referenced via refkey will be imported as type-only
|
|
20
|
+
* (inside a `if TYPE_CHECKING:` block) unless also used as values elsewhere.
|
|
15
21
|
*/
|
|
16
22
|
export function TypeReference(props: TypeReferenceProps) {
|
|
17
23
|
const type = props.refkey ? props.refkey : props.name;
|
|
@@ -21,13 +27,15 @@ export function TypeReference(props: TypeReferenceProps) {
|
|
|
21
27
|
: undefined;
|
|
22
28
|
|
|
23
29
|
return (
|
|
24
|
-
<
|
|
25
|
-
<
|
|
30
|
+
<TypeRefContext>
|
|
31
|
+
<group>
|
|
32
|
+
<indent>
|
|
33
|
+
<sbr />
|
|
34
|
+
{type}
|
|
35
|
+
<Show when={Boolean(typeArgs)}>{typeArgs}</Show>
|
|
36
|
+
</indent>
|
|
26
37
|
<sbr />
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
</indent>
|
|
30
|
-
<sbr />
|
|
31
|
-
</group>
|
|
38
|
+
</group>
|
|
39
|
+
</TypeRefContext>
|
|
32
40
|
);
|
|
33
41
|
}
|
|
@@ -10,6 +10,7 @@ import { createPythonSymbol } from "../symbol-creation.js";
|
|
|
10
10
|
import { Atom } from "./Atom.jsx";
|
|
11
11
|
import { BaseDeclarationProps } from "./Declaration.jsx";
|
|
12
12
|
import { SimpleCommentBlock } from "./PyDoc.jsx";
|
|
13
|
+
import { TypeRefContext } from "./TypeRefContext.jsx";
|
|
13
14
|
|
|
14
15
|
export interface VariableDeclarationProps extends BaseDeclarationProps {
|
|
15
16
|
/**
|
|
@@ -93,7 +94,10 @@ export function VariableDeclaration(props: VariableDeclarationProps) {
|
|
|
93
94
|
if (!props.type || props.callStatementVar) return undefined;
|
|
94
95
|
return (
|
|
95
96
|
<>
|
|
96
|
-
:
|
|
97
|
+
:{" "}
|
|
98
|
+
<TypeRefContext>
|
|
99
|
+
<TypeSymbolSlot>{props.type}</TypeSymbolSlot>
|
|
100
|
+
</TypeRefContext>
|
|
97
101
|
</>
|
|
98
102
|
);
|
|
99
103
|
});
|
package/src/components/index.ts
CHANGED
|
@@ -13,7 +13,6 @@ export type { CommonFunctionProps } from "./FunctionBase.js";
|
|
|
13
13
|
export * from "./FunctionCallExpression.js";
|
|
14
14
|
export * from "./FunctionDeclaration.js";
|
|
15
15
|
export * from "./FutureStatement.js";
|
|
16
|
-
export * from "./ImportStatement.js";
|
|
17
16
|
export * from "./LexicalScope.js";
|
|
18
17
|
export * from "./MemberExpression.js";
|
|
19
18
|
export * from "./MemberScope.jsx";
|
|
@@ -27,6 +26,7 @@ export * from "./SourceFile.js";
|
|
|
27
26
|
export * from "./StatementList.js";
|
|
28
27
|
export * from "./StaticMethodDeclaration.js";
|
|
29
28
|
export * from "./TypeArguments.js";
|
|
29
|
+
export * from "./TypeRefContext.js";
|
|
30
30
|
export * from "./TypeReference.js";
|
|
31
31
|
export * from "./UnionTypeExpression.js";
|
|
32
32
|
export * from "./VariableDeclaration.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./type-ref-context.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ComponentContext, createContext, useContext } from "@alloy-js/core";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Context for tracking whether we are in a type annotation position.
|
|
5
|
+
* Used to determine if imports should be guarded with TYPE_CHECKING.
|
|
6
|
+
*
|
|
7
|
+
* @internal Use the TypeRefContext component instead.
|
|
8
|
+
*/
|
|
9
|
+
export const TypeRefContextDef: ComponentContext<true> = createContext<true>();
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @returns 'true' if in a type context, 'false' if in a value context.
|
|
13
|
+
*/
|
|
14
|
+
export function isTypeRefContext(): boolean {
|
|
15
|
+
return useContext(TypeRefContextDef) === true;
|
|
16
|
+
}
|
|
@@ -1,21 +1,15 @@
|
|
|
1
|
+
import { OutputSymbol } from "@alloy-js/core";
|
|
1
2
|
import { PythonOutputSymbol } from "./symbols/python-output-symbol.js";
|
|
2
3
|
|
|
3
|
-
export function pythonNameConflictResolver(
|
|
4
|
-
_: string,
|
|
5
|
-
symbols: PythonOutputSymbol[],
|
|
6
|
-
) {
|
|
4
|
+
export function pythonNameConflictResolver(_: string, symbols: OutputSymbol[]) {
|
|
7
5
|
for (let i = 1; i < symbols.length; i++) {
|
|
6
|
+
const symbol = symbols[i] as PythonOutputSymbol;
|
|
8
7
|
// Rename all but the first symbol to have a suffix of _2, _3, plus the scope name if available.
|
|
9
|
-
const symbol = symbols[i] as unknown as {
|
|
10
|
-
originalName: string;
|
|
11
|
-
name: string;
|
|
12
|
-
module?: string;
|
|
13
|
-
};
|
|
14
8
|
symbol.name =
|
|
15
9
|
symbol.originalName +
|
|
16
10
|
"_" +
|
|
17
11
|
(i + 1) +
|
|
18
12
|
"_" +
|
|
19
|
-
(
|
|
13
|
+
(symbol.aliasTarget?.scope?.name ?? symbol.module ?? "");
|
|
20
14
|
}
|
|
21
15
|
}
|