@alloy-js/python 0.4.0-dev.5 → 0.4.0-dev.7
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/name-conflict-resolver.js +6 -2
- package/dist/dev/src/name-conflict-resolver.js.map +1 -1
- package/dist/dev/test/name-conflict.test.js +38 -0
- package/dist/dev/test/name-conflict.test.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 +6 -2
- package/dist/src/name-conflict-resolver.js.map +1 -1
- package/dist/test/name-conflict.test.d.ts +2 -0
- package/dist/test/name-conflict.test.d.ts.map +1 -0
- package/dist/test/name-conflict.test.js +38 -0
- package/dist/test/name-conflict.test.js.map +1 -0
- 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 +4 -4
- package/src/name-conflict-resolver.ts +9 -11
- package/test/name-conflict.test.ts +37 -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.7",
|
|
4
4
|
"description": "Python bindings for Alloy",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
"author": "",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@alloy-js/core": "~0.22.0 || >= 0.23.0-dev.
|
|
23
|
+
"@alloy-js/core": "~0.22.0 || >= 0.23.0-dev.18",
|
|
24
24
|
"change-case": "^5.4.4",
|
|
25
25
|
"pathe": "^2.0.3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@alloy-js/cli": "~0.22.0 || >= 0.23.0-dev.
|
|
29
|
-
"@alloy-js/rollup-plugin": "~0.1.0 || >= 0.1.1-dev.
|
|
28
|
+
"@alloy-js/cli": "~0.22.0 || >= 0.23.0-dev.6",
|
|
29
|
+
"@alloy-js/rollup-plugin": "~0.1.0 || >= 0.1.1-dev.2",
|
|
30
30
|
"@microsoft/api-extractor": "~7.52.8",
|
|
31
31
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
32
32
|
"concurrently": "^9.2.0",
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
+
import { OutputSymbol } from "@alloy-js/core";
|
|
1
2
|
import { PythonOutputSymbol } from "./symbols/python-output-symbol.js";
|
|
2
3
|
|
|
3
|
-
export function pythonNameConflictResolver(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export function pythonNameConflictResolver(_: string, symbols: OutputSymbol[]) {
|
|
5
|
+
if (symbols.length === 0) return;
|
|
6
|
+
// Clear any prior deconflict rename on the first symbol so it reverts to
|
|
7
|
+
// the plain name once a collision is resolved.
|
|
8
|
+
symbols[0].deconflictedName = undefined;
|
|
7
9
|
for (let i = 1; i < symbols.length; i++) {
|
|
10
|
+
const symbol = symbols[i] as PythonOutputSymbol;
|
|
8
11
|
// Rename all but the first symbol to have a suffix of _2, _3, plus the scope name if available.
|
|
9
|
-
|
|
10
|
-
originalName: string;
|
|
11
|
-
name: string;
|
|
12
|
-
module?: string;
|
|
13
|
-
};
|
|
14
|
-
symbol.name =
|
|
12
|
+
symbol.deconflictedName =
|
|
15
13
|
symbol.originalName +
|
|
16
14
|
"_" +
|
|
17
15
|
(i + 1) +
|
|
18
16
|
"_" +
|
|
19
|
-
(
|
|
17
|
+
(symbol.aliasTarget?.scope?.name ?? symbol.module ?? "");
|
|
20
18
|
}
|
|
21
19
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createOutputBinder } from "@alloy-js/core";
|
|
2
|
+
import { expect, it } from "vitest";
|
|
3
|
+
import { pythonNameConflictResolver } from "../src/name-conflict-resolver.js";
|
|
4
|
+
import { createPythonSymbol } from "../src/symbol-creation.js";
|
|
5
|
+
import { PythonModuleScope } from "../src/symbols/index.js";
|
|
6
|
+
|
|
7
|
+
it("reverts Python's non-`_N` rename scheme when the conflict is removed", () => {
|
|
8
|
+
// Python renames via `foo_2_modulename` — the old regex-based revert would
|
|
9
|
+
// never match this pattern. The deconflictedName slot is pattern-agnostic,
|
|
10
|
+
// so invoking the resolver with the survivor alone clears the rename
|
|
11
|
+
// regardless of scheme.
|
|
12
|
+
const binder = createOutputBinder();
|
|
13
|
+
const scope = new PythonModuleScope("root", undefined, { binder });
|
|
14
|
+
|
|
15
|
+
const a = createPythonSymbol("foo", scope.symbols);
|
|
16
|
+
const b = createPythonSymbol("foo", scope.symbols);
|
|
17
|
+
|
|
18
|
+
// Simulate a conflict pass.
|
|
19
|
+
pythonNameConflictResolver("foo", [a, b]);
|
|
20
|
+
expect(a.name).toBe("foo");
|
|
21
|
+
expect(b.name).not.toBe("foo");
|
|
22
|
+
expect(b.deconflictedName).toBeDefined();
|
|
23
|
+
|
|
24
|
+
// Simulate the post-delete deconflict pass — the sole survivor must have
|
|
25
|
+
// its prior rename cleared, even though its "rename scheme" differs from
|
|
26
|
+
// the default `_N` shape.
|
|
27
|
+
b.deconflictedName = "foo_2_module"; // pretend b had been renamed using python scheme
|
|
28
|
+
pythonNameConflictResolver("foo", [a]);
|
|
29
|
+
expect(a.name).toBe("foo");
|
|
30
|
+
expect(a.deconflictedName).toBeUndefined();
|
|
31
|
+
|
|
32
|
+
// And if a was the one carrying the prior rename:
|
|
33
|
+
a.deconflictedName = "foo_3_other";
|
|
34
|
+
pythonNameConflictResolver("foo", [a]);
|
|
35
|
+
expect(a.name).toBe("foo");
|
|
36
|
+
expect(a.deconflictedName).toBeUndefined();
|
|
37
|
+
});
|