@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
|
@@ -73,7 +73,10 @@ describe("DataclassDeclaration", () => {
|
|
|
73
73
|
expect(res).toRenderTo(
|
|
74
74
|
d`
|
|
75
75
|
from dataclasses import dataclass
|
|
76
|
-
from
|
|
76
|
+
from typing import TYPE_CHECKING
|
|
77
|
+
|
|
78
|
+
if TYPE_CHECKING:
|
|
79
|
+
from dataclasses import KW_ONLY
|
|
77
80
|
|
|
78
81
|
|
|
79
82
|
@dataclass
|
|
@@ -624,7 +627,10 @@ describe("DataclassDeclaration", () => {
|
|
|
624
627
|
name="user"
|
|
625
628
|
type={userRefkey}
|
|
626
629
|
initializer={
|
|
627
|
-
<py.ClassInstantiation
|
|
630
|
+
<py.ClassInstantiation
|
|
631
|
+
target={userRefkey}
|
|
632
|
+
args={["1", '"Alice"']}
|
|
633
|
+
/>
|
|
628
634
|
}
|
|
629
635
|
/>
|
|
630
636
|
<hbr />
|
package/test/externals.test.tsx
CHANGED
|
@@ -92,7 +92,10 @@ it("uses import from external library in multiple functions", () => {
|
|
|
92
92
|
const expected = d`
|
|
93
93
|
from requests import get
|
|
94
94
|
from requests import post
|
|
95
|
-
from
|
|
95
|
+
from typing import TYPE_CHECKING
|
|
96
|
+
|
|
97
|
+
if TYPE_CHECKING:
|
|
98
|
+
from requests.models import Response
|
|
96
99
|
|
|
97
100
|
|
|
98
101
|
def get_user(user_id: int) -> Response:
|
|
@@ -169,7 +172,10 @@ it("uses import from external library in multiple class methods", () => {
|
|
|
169
172
|
const expected = d`
|
|
170
173
|
from requests import get
|
|
171
174
|
from requests import post
|
|
172
|
-
from
|
|
175
|
+
from typing import TYPE_CHECKING
|
|
176
|
+
|
|
177
|
+
if TYPE_CHECKING:
|
|
178
|
+
from requests.models import Response
|
|
173
179
|
|
|
174
180
|
|
|
175
181
|
class UserClient:
|
|
@@ -450,9 +450,12 @@ describe("Function Declaration", () => {
|
|
|
450
450
|
|
|
451
451
|
`,
|
|
452
452
|
"usage.py": `
|
|
453
|
-
from
|
|
454
|
-
|
|
455
|
-
|
|
453
|
+
from typing import TYPE_CHECKING
|
|
454
|
+
|
|
455
|
+
if TYPE_CHECKING:
|
|
456
|
+
from mod1 import Foo
|
|
457
|
+
from mod2 import A
|
|
458
|
+
from mod2 import B
|
|
456
459
|
|
|
457
460
|
|
|
458
461
|
async def foo(x: A, y: B, *args, **kwargs) -> Foo:
|
package/test/imports.test.tsx
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { refkey } from "@alloy-js/core";
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ImportStatement,
|
|
5
|
+
ImportStatements,
|
|
6
|
+
} from "../src/components/ImportStatement.jsx";
|
|
4
7
|
import * as py from "../src/index.js";
|
|
5
8
|
import { createPythonSymbol } from "../src/symbol-creation.js";
|
|
6
9
|
import { ImportedSymbol, ImportRecords } from "../src/symbols/index.js";
|
|
@@ -56,7 +59,7 @@ describe("ImportStatements", () => {
|
|
|
56
59
|
[sysModuleScope, { symbols: new Set<ImportedSymbol>() }],
|
|
57
60
|
]);
|
|
58
61
|
|
|
59
|
-
const result = toSourceText([<
|
|
62
|
+
const result = toSourceText([<ImportStatements records={records} />]);
|
|
60
63
|
const expected = `
|
|
61
64
|
from math import pi
|
|
62
65
|
from math import sqrt
|
|
@@ -85,10 +88,7 @@ describe("ImportStatements", () => {
|
|
|
85
88
|
]);
|
|
86
89
|
|
|
87
90
|
const result = toSourceText([
|
|
88
|
-
<
|
|
89
|
-
records={records}
|
|
90
|
-
joinImportsFromSameModule={true}
|
|
91
|
-
/>,
|
|
91
|
+
<ImportStatements records={records} joinImportsFromSameModule={true} />,
|
|
92
92
|
]);
|
|
93
93
|
const expected = `
|
|
94
94
|
from math import pi, sqrt
|
package/test/references.test.tsx
CHANGED
|
@@ -312,7 +312,7 @@ it("only futureImports before definition", () => {
|
|
|
312
312
|
const content = (
|
|
313
313
|
<py.SourceFile
|
|
314
314
|
path="test.py"
|
|
315
|
-
futureImports={<py.FutureStatement feature="annotations" />}
|
|
315
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
316
316
|
>
|
|
317
317
|
<py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
|
|
318
318
|
</py.SourceFile>
|
|
@@ -333,7 +333,7 @@ it("only futureImports before non-definition", () => {
|
|
|
333
333
|
const content = (
|
|
334
334
|
<py.SourceFile
|
|
335
335
|
path="test.py"
|
|
336
|
-
futureImports={<py.FutureStatement feature="annotations" />}
|
|
336
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
337
337
|
>
|
|
338
338
|
<py.VariableDeclaration name="x" initializer={42} />
|
|
339
339
|
</py.SourceFile>
|
|
@@ -393,7 +393,7 @@ it("doc + futureImports before definition", () => {
|
|
|
393
393
|
<py.SourceFile
|
|
394
394
|
path="test.py"
|
|
395
395
|
doc={moduleDoc}
|
|
396
|
-
futureImports={<py.FutureStatement feature="annotations" />}
|
|
396
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
397
397
|
>
|
|
398
398
|
<py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
|
|
399
399
|
</py.SourceFile>
|
|
@@ -423,7 +423,7 @@ it("doc + futureImports before non-definition", () => {
|
|
|
423
423
|
<py.SourceFile
|
|
424
424
|
path="test.py"
|
|
425
425
|
doc={moduleDoc}
|
|
426
|
-
futureImports={<py.FutureStatement feature="annotations" />}
|
|
426
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
427
427
|
>
|
|
428
428
|
<py.VariableDeclaration name="x" initializer={42} />
|
|
429
429
|
</py.SourceFile>
|
|
@@ -498,7 +498,7 @@ it("futureImports + imports before definition", () => {
|
|
|
498
498
|
const content = (
|
|
499
499
|
<py.SourceFile
|
|
500
500
|
path="test.py"
|
|
501
|
-
futureImports={<py.FutureStatement feature="annotations" />}
|
|
501
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
502
502
|
>
|
|
503
503
|
<py.DataclassDeclaration name="User">
|
|
504
504
|
<py.VariableDeclaration name="name" type="str" />
|
|
@@ -525,7 +525,7 @@ it("futureImports + imports before non-definition", () => {
|
|
|
525
525
|
const content = (
|
|
526
526
|
<py.SourceFile
|
|
527
527
|
path="test.py"
|
|
528
|
-
futureImports={<py.FutureStatement feature="annotations" />}
|
|
528
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
529
529
|
>
|
|
530
530
|
<py.VariableDeclaration
|
|
531
531
|
name="x"
|
|
@@ -552,7 +552,7 @@ it("doc + futureImports + imports before definition", () => {
|
|
|
552
552
|
<py.SourceFile
|
|
553
553
|
path="test.py"
|
|
554
554
|
doc={moduleDoc}
|
|
555
|
-
futureImports={<py.FutureStatement feature="annotations" />}
|
|
555
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
556
556
|
>
|
|
557
557
|
<py.DataclassDeclaration name="User">
|
|
558
558
|
<py.VariableDeclaration name="name" type="str" />
|
|
@@ -588,7 +588,7 @@ it("doc + futureImports + imports before non-definition", () => {
|
|
|
588
588
|
<py.SourceFile
|
|
589
589
|
path="test.py"
|
|
590
590
|
doc={moduleDoc}
|
|
591
|
-
futureImports={<py.FutureStatement feature="annotations" />}
|
|
591
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
592
592
|
>
|
|
593
593
|
<py.VariableDeclaration
|
|
594
594
|
name="x"
|
|
@@ -642,7 +642,7 @@ it("only futureImports in file (no children)", () => {
|
|
|
642
642
|
const content = (
|
|
643
643
|
<py.SourceFile
|
|
644
644
|
path="test.py"
|
|
645
|
-
futureImports={<py.FutureStatement feature="annotations" />}
|
|
645
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
646
646
|
/>
|
|
647
647
|
);
|
|
648
648
|
|
|
@@ -661,7 +661,7 @@ it("doc + futureImports in file (no children)", () => {
|
|
|
661
661
|
<py.SourceFile
|
|
662
662
|
path="test.py"
|
|
663
663
|
doc={moduleDoc}
|
|
664
|
-
futureImports={<py.FutureStatement feature="annotations" />}
|
|
664
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
665
665
|
/>
|
|
666
666
|
);
|
|
667
667
|
|
|
@@ -743,7 +743,7 @@ it("headerComment + futureImports before definition", () => {
|
|
|
743
743
|
<py.SourceFile
|
|
744
744
|
path="test.py"
|
|
745
745
|
headerComment="Copyright 2024 My Company"
|
|
746
|
-
futureImports={<py.FutureStatement feature="annotations" />}
|
|
746
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
747
747
|
>
|
|
748
748
|
<py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
|
|
749
749
|
</py.SourceFile>
|
|
@@ -797,7 +797,7 @@ it("headerComment + doc + futureImports before definition", () => {
|
|
|
797
797
|
path="test.py"
|
|
798
798
|
headerComment="Copyright 2024 My Company"
|
|
799
799
|
doc={moduleDoc}
|
|
800
|
-
futureImports={<py.FutureStatement feature="annotations" />}
|
|
800
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
801
801
|
>
|
|
802
802
|
<py.FunctionDeclaration name="hello">pass</py.FunctionDeclaration>
|
|
803
803
|
</py.SourceFile>
|
|
@@ -829,7 +829,7 @@ it("headerComment + doc + futureImports + imports before definition", () => {
|
|
|
829
829
|
path="test.py"
|
|
830
830
|
headerComment="Copyright 2024 My Company"
|
|
831
831
|
doc={moduleDoc}
|
|
832
|
-
futureImports={<py.FutureStatement feature="annotations" />}
|
|
832
|
+
futureImports={[<py.FutureStatement feature="annotations" />]}
|
|
833
833
|
>
|
|
834
834
|
<py.DataclassDeclaration name="User">
|
|
835
835
|
<py.VariableDeclaration name="name" type="str" />
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { refkey } from "@alloy-js/core";
|
|
2
|
+
import { describe, it } from "vitest";
|
|
3
|
+
import { createModule } from "../src/create-module.js";
|
|
4
|
+
import * as py from "../src/index.js";
|
|
5
|
+
import { assertFileContents, toSourceTextMultiple } from "./utils.jsx";
|
|
6
|
+
|
|
7
|
+
describe("TYPE_CHECKING imports", () => {
|
|
8
|
+
it("imports type-only references inside TYPE_CHECKING block", () => {
|
|
9
|
+
const userClassRef = refkey();
|
|
10
|
+
|
|
11
|
+
const result = toSourceTextMultiple([
|
|
12
|
+
<py.SourceFile path="models.py">
|
|
13
|
+
<py.ClassDeclaration name="User" refkey={userClassRef} />
|
|
14
|
+
</py.SourceFile>,
|
|
15
|
+
<py.SourceFile path="service.py">
|
|
16
|
+
<py.FunctionDeclaration
|
|
17
|
+
name="process_user"
|
|
18
|
+
parameters={[{ name: "user", type: userClassRef }]}
|
|
19
|
+
returnType="None"
|
|
20
|
+
>
|
|
21
|
+
pass
|
|
22
|
+
</py.FunctionDeclaration>
|
|
23
|
+
</py.SourceFile>,
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
assertFileContents(result, {
|
|
27
|
+
"models.py": `
|
|
28
|
+
class User:
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
`,
|
|
32
|
+
"service.py": `
|
|
33
|
+
from typing import TYPE_CHECKING
|
|
34
|
+
|
|
35
|
+
if TYPE_CHECKING:
|
|
36
|
+
from models import User
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def process_user(user: User) -> None:
|
|
40
|
+
pass
|
|
41
|
+
|
|
42
|
+
`,
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("imports value references outside TYPE_CHECKING block", () => {
|
|
47
|
+
const userClassRef = refkey();
|
|
48
|
+
|
|
49
|
+
const result = toSourceTextMultiple([
|
|
50
|
+
<py.SourceFile path="models.py">
|
|
51
|
+
<py.ClassDeclaration name="User" refkey={userClassRef} />
|
|
52
|
+
</py.SourceFile>,
|
|
53
|
+
<py.SourceFile path="service.py">
|
|
54
|
+
<py.FunctionDeclaration name="create_user" returnType="None">
|
|
55
|
+
<py.VariableDeclaration
|
|
56
|
+
name="user"
|
|
57
|
+
initializer={<py.ClassInstantiation target={userClassRef} />}
|
|
58
|
+
/>
|
|
59
|
+
</py.FunctionDeclaration>
|
|
60
|
+
</py.SourceFile>,
|
|
61
|
+
]);
|
|
62
|
+
|
|
63
|
+
assertFileContents(result, {
|
|
64
|
+
"models.py": `
|
|
65
|
+
class User:
|
|
66
|
+
pass
|
|
67
|
+
|
|
68
|
+
`,
|
|
69
|
+
"service.py": `
|
|
70
|
+
from models import User
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def create_user() -> None:
|
|
74
|
+
user = User()
|
|
75
|
+
|
|
76
|
+
`,
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("upgrades type-only import to regular import when also used as value", () => {
|
|
81
|
+
const userClassRef = refkey();
|
|
82
|
+
|
|
83
|
+
const result = toSourceTextMultiple([
|
|
84
|
+
<py.SourceFile path="models.py">
|
|
85
|
+
<py.ClassDeclaration name="User" refkey={userClassRef} />
|
|
86
|
+
</py.SourceFile>,
|
|
87
|
+
<py.SourceFile path="service.py">
|
|
88
|
+
<py.FunctionDeclaration
|
|
89
|
+
name="create_user"
|
|
90
|
+
parameters={[{ name: "existing", type: userClassRef }]}
|
|
91
|
+
returnType={userClassRef}
|
|
92
|
+
>
|
|
93
|
+
<py.StatementList>
|
|
94
|
+
<py.VariableDeclaration
|
|
95
|
+
name="user"
|
|
96
|
+
initializer={<py.ClassInstantiation target={userClassRef} />}
|
|
97
|
+
/>
|
|
98
|
+
<>return user</>
|
|
99
|
+
</py.StatementList>
|
|
100
|
+
</py.FunctionDeclaration>
|
|
101
|
+
</py.SourceFile>,
|
|
102
|
+
]);
|
|
103
|
+
|
|
104
|
+
// Since User is used both as a type (parameter type, return type) and
|
|
105
|
+
// as a value (ClassInstantiation), it should be a regular import
|
|
106
|
+
assertFileContents(result, {
|
|
107
|
+
"models.py": `
|
|
108
|
+
class User:
|
|
109
|
+
pass
|
|
110
|
+
|
|
111
|
+
`,
|
|
112
|
+
"service.py": `
|
|
113
|
+
from models import User
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def create_user(existing: User) -> User:
|
|
117
|
+
user = User()
|
|
118
|
+
return user
|
|
119
|
+
|
|
120
|
+
`,
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("handles mixed type-only and regular imports from same module", () => {
|
|
125
|
+
const userClassRef = refkey();
|
|
126
|
+
const helperFuncRef = refkey();
|
|
127
|
+
|
|
128
|
+
const result = toSourceTextMultiple([
|
|
129
|
+
<py.SourceFile path="models.py">
|
|
130
|
+
<py.ClassDeclaration name="User" refkey={userClassRef} />
|
|
131
|
+
<py.FunctionDeclaration name="helper" refkey={helperFuncRef}>
|
|
132
|
+
pass
|
|
133
|
+
</py.FunctionDeclaration>
|
|
134
|
+
</py.SourceFile>,
|
|
135
|
+
<py.SourceFile path="service.py">
|
|
136
|
+
<py.FunctionDeclaration
|
|
137
|
+
name="process"
|
|
138
|
+
parameters={[{ name: "user", type: userClassRef }]}
|
|
139
|
+
returnType="None"
|
|
140
|
+
>
|
|
141
|
+
<py.FunctionCallExpression target={helperFuncRef} />
|
|
142
|
+
</py.FunctionDeclaration>
|
|
143
|
+
</py.SourceFile>,
|
|
144
|
+
]);
|
|
145
|
+
|
|
146
|
+
// helper is used as a value (function call), User is only used as type
|
|
147
|
+
assertFileContents(result, {
|
|
148
|
+
"models.py": `
|
|
149
|
+
class User:
|
|
150
|
+
pass
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def helper():
|
|
154
|
+
pass
|
|
155
|
+
|
|
156
|
+
`,
|
|
157
|
+
"service.py": `
|
|
158
|
+
from models import helper
|
|
159
|
+
from typing import TYPE_CHECKING
|
|
160
|
+
|
|
161
|
+
if TYPE_CHECKING:
|
|
162
|
+
from models import User
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def process(user: User) -> None:
|
|
166
|
+
helper()
|
|
167
|
+
|
|
168
|
+
`,
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("handles return type as type-only import", () => {
|
|
173
|
+
const resultTypeRef = refkey();
|
|
174
|
+
|
|
175
|
+
const result = toSourceTextMultiple([
|
|
176
|
+
<py.SourceFile path="types.py">
|
|
177
|
+
<py.ClassDeclaration name="Result" refkey={resultTypeRef} />
|
|
178
|
+
</py.SourceFile>,
|
|
179
|
+
<py.SourceFile path="main.py">
|
|
180
|
+
<py.FunctionDeclaration name="get_result" returnType={resultTypeRef}>
|
|
181
|
+
pass
|
|
182
|
+
</py.FunctionDeclaration>
|
|
183
|
+
</py.SourceFile>,
|
|
184
|
+
]);
|
|
185
|
+
|
|
186
|
+
assertFileContents(result, {
|
|
187
|
+
"types.py": `
|
|
188
|
+
class Result:
|
|
189
|
+
pass
|
|
190
|
+
|
|
191
|
+
`,
|
|
192
|
+
"main.py": `
|
|
193
|
+
from typing import TYPE_CHECKING
|
|
194
|
+
|
|
195
|
+
if TYPE_CHECKING:
|
|
196
|
+
from types import Result
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def get_result() -> Result:
|
|
200
|
+
pass
|
|
201
|
+
|
|
202
|
+
`,
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("handles variable type annotation as type-only import", () => {
|
|
207
|
+
const configTypeRef = refkey();
|
|
208
|
+
|
|
209
|
+
const result = toSourceTextMultiple([
|
|
210
|
+
<py.SourceFile path="types.py">
|
|
211
|
+
<py.ClassDeclaration name="Config" refkey={configTypeRef} />
|
|
212
|
+
</py.SourceFile>,
|
|
213
|
+
<py.SourceFile path="main.py">
|
|
214
|
+
<py.VariableDeclaration name="config" type={configTypeRef} omitNone />
|
|
215
|
+
</py.SourceFile>,
|
|
216
|
+
]);
|
|
217
|
+
|
|
218
|
+
assertFileContents(result, {
|
|
219
|
+
"types.py": `
|
|
220
|
+
class Config:
|
|
221
|
+
pass
|
|
222
|
+
|
|
223
|
+
`,
|
|
224
|
+
"main.py": `
|
|
225
|
+
from typing import TYPE_CHECKING
|
|
226
|
+
|
|
227
|
+
if TYPE_CHECKING:
|
|
228
|
+
from types import Config
|
|
229
|
+
|
|
230
|
+
config: Config
|
|
231
|
+
`,
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("handles TypeReference component as type-only import", () => {
|
|
236
|
+
const myTypeRef = refkey();
|
|
237
|
+
|
|
238
|
+
const result = toSourceTextMultiple([
|
|
239
|
+
<py.SourceFile path="types.py">
|
|
240
|
+
<py.ClassDeclaration name="MyType" refkey={myTypeRef} />
|
|
241
|
+
</py.SourceFile>,
|
|
242
|
+
<py.SourceFile path="main.py">
|
|
243
|
+
<py.VariableDeclaration
|
|
244
|
+
name="value"
|
|
245
|
+
type={<py.TypeReference refkey={myTypeRef} />}
|
|
246
|
+
omitNone
|
|
247
|
+
/>
|
|
248
|
+
</py.SourceFile>,
|
|
249
|
+
]);
|
|
250
|
+
|
|
251
|
+
assertFileContents(result, {
|
|
252
|
+
"types.py": `
|
|
253
|
+
class MyType:
|
|
254
|
+
pass
|
|
255
|
+
|
|
256
|
+
`,
|
|
257
|
+
"main.py": `
|
|
258
|
+
from typing import TYPE_CHECKING
|
|
259
|
+
|
|
260
|
+
if TYPE_CHECKING:
|
|
261
|
+
from types import MyType
|
|
262
|
+
|
|
263
|
+
value: MyType
|
|
264
|
+
`,
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it("handles class bases as regular import (runtime requirement)", () => {
|
|
269
|
+
const baseClassRef = refkey();
|
|
270
|
+
|
|
271
|
+
const result = toSourceTextMultiple([
|
|
272
|
+
<py.SourceFile path="base.py">
|
|
273
|
+
<py.ClassDeclaration name="BaseClass" refkey={baseClassRef} />
|
|
274
|
+
</py.SourceFile>,
|
|
275
|
+
<py.SourceFile path="derived.py">
|
|
276
|
+
<py.ClassDeclaration name="DerivedClass" bases={[baseClassRef]} />
|
|
277
|
+
</py.SourceFile>,
|
|
278
|
+
]);
|
|
279
|
+
|
|
280
|
+
// Class bases require runtime access, so they should NOT be
|
|
281
|
+
// inside a TYPE_CHECKING block
|
|
282
|
+
assertFileContents(result, {
|
|
283
|
+
"base.py": `
|
|
284
|
+
class BaseClass:
|
|
285
|
+
pass
|
|
286
|
+
|
|
287
|
+
`,
|
|
288
|
+
"derived.py": `
|
|
289
|
+
from base import BaseClass
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
class DerivedClass(BaseClass):
|
|
293
|
+
pass
|
|
294
|
+
|
|
295
|
+
`,
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it("renders regular imports before TYPE_CHECKING block", () => {
|
|
300
|
+
// Create a typing module with multiple exports
|
|
301
|
+
const typingModule = createModule({
|
|
302
|
+
name: "typing",
|
|
303
|
+
descriptor: {
|
|
304
|
+
".": ["TYPE_CHECKING", "cast"],
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
// Create a third-party module
|
|
309
|
+
const requestsModule = createModule({
|
|
310
|
+
name: "requests",
|
|
311
|
+
descriptor: {
|
|
312
|
+
".": ["get"],
|
|
313
|
+
},
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
const userClassRef = refkey();
|
|
317
|
+
|
|
318
|
+
const result = toSourceTextMultiple(
|
|
319
|
+
[
|
|
320
|
+
<py.SourceFile path="models.py">
|
|
321
|
+
<py.ClassDeclaration name="User" refkey={userClassRef} />
|
|
322
|
+
</py.SourceFile>,
|
|
323
|
+
<py.SourceFile path="service.py">
|
|
324
|
+
<py.FunctionDeclaration
|
|
325
|
+
name="get_users"
|
|
326
|
+
parameters={[{ name: "user", type: userClassRef }]}
|
|
327
|
+
returnType="str"
|
|
328
|
+
>
|
|
329
|
+
<py.StatementList>
|
|
330
|
+
{/* Use cast as a value (function call) to make it a regular import */}
|
|
331
|
+
<>response = {requestsModule["."].get}("https://example.com")</>
|
|
332
|
+
<>return {typingModule["."].cast}(str, user)</>
|
|
333
|
+
</py.StatementList>
|
|
334
|
+
</py.FunctionDeclaration>
|
|
335
|
+
</py.SourceFile>,
|
|
336
|
+
],
|
|
337
|
+
{ externals: [typingModule, requestsModule] },
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
// Regular imports first (sorted alphabetically), then TYPE_CHECKING block
|
|
341
|
+
assertFileContents(result, {
|
|
342
|
+
"models.py": `
|
|
343
|
+
class User:
|
|
344
|
+
pass
|
|
345
|
+
|
|
346
|
+
`,
|
|
347
|
+
"service.py": `
|
|
348
|
+
from requests import get
|
|
349
|
+
from typing import cast
|
|
350
|
+
from typing import TYPE_CHECKING
|
|
351
|
+
|
|
352
|
+
if TYPE_CHECKING:
|
|
353
|
+
from models import User
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
def get_users(user: User) -> str:
|
|
357
|
+
response = get("https://example.com")
|
|
358
|
+
return cast(str, user)
|
|
359
|
+
|
|
360
|
+
`,
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
});
|
package/test/variables.test.tsx
CHANGED
package/vitest.config.ts
CHANGED
|
@@ -2,6 +2,14 @@ import alloyPlugin from "@alloy-js/rollup-plugin";
|
|
|
2
2
|
import { defineConfig } from "vitest/config";
|
|
3
3
|
|
|
4
4
|
export default defineConfig({
|
|
5
|
+
resolve: {
|
|
6
|
+
conditions: ["source"],
|
|
7
|
+
},
|
|
8
|
+
ssr: {
|
|
9
|
+
resolve: {
|
|
10
|
+
conditions: ["source"],
|
|
11
|
+
},
|
|
12
|
+
},
|
|
5
13
|
esbuild: {
|
|
6
14
|
jsx: "preserve",
|
|
7
15
|
sourcemap: "both",
|