Skip to content

Commit e206a55

Browse files
committed
support symbol transpilation
1 parent b30638c commit e206a55

5 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/parseInlineType.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ export const tryToParseInlineType = (
7272
// there is no way to represent template literals in Python,
7373
// so we fallback to string
7474
return "str";
75+
} else if (type.flags & TypeFlags.ESSymbol) {
76+
state.imports.add("Any");
77+
return "Any";
7578
} else {
7679
// assume interface or object, we need to create a helper type
7780
if (!globalScope) {

src/parseProperty.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const getDocumentationStringForDict = (
7676
.join(" \n");
7777

7878
if (documentation.length > 0) {
79-
return `${JSON.stringify(name)}: ${documentation}`;
79+
return `\`${JSON.stringify(name)}\`: ${documentation}`;
8080
} else {
8181
return undefined;
8282
}

src/parseTypeDefinition.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ export const parseTypeDefinition = (
5959
const propertyDocumentation = properties
6060
.map((v) => getDocumentationStringForDict(state, v))
6161
.filter((v) => !!v)
62+
.map((v) => `- ${v}`.replaceAll("\n", "\n "))
6263
.join("\n");
6364

6465
const innerDocstring =
65-
(documentation ?? "").replaceAll("\n", " \n") +
66+
(documentation ?? "").replaceAll("\n", "\n ") +
6667
(propertyDocumentation.length > 0
6768
? "\n## Entries\n" + propertyDocumentation
6869
: "");

src/testing/basic.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ describe("transpiling basic types", () => {
6262
"from typing_extensions import Union\n\nT = Union[None,float]",
6363
],
6464
["export type T = `a.b.${string}`", "T = str"],
65+
["export type T = symbol", "from typing_extensions import Any\n\nT = Any"],
6566
])("transpiles %p to %p", async (input, expected) => {
6667
const result = await transpileString(input);
6768
expect(result).toEqual(expected);

src/testing/dicts.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ A = TypedDict("A", {
133133
"""
134134
This is A
135135
## Entries
136-
"foo.bar": this is foo.bar
137-
"a/b": this is a/b
136+
- \`"foo.bar"\`: this is foo.bar
137+
- \`"a/b"\`: this is a/b
138138
"""`);
139139
});
140140
});

0 commit comments

Comments
 (0)