diff --git a/generators/python-v2/ast/src/PythonFile.ts b/generators/python-v2/ast/src/PythonFile.ts index 4e386c1aa85..558bde6b910 100644 --- a/generators/python-v2/ast/src/PythonFile.ts +++ b/generators/python-v2/ast/src/PythonFile.ts @@ -90,6 +90,11 @@ export class PythonFile extends AstNode { const usedNames = this.getInitialUsedNames(); references.forEach((reference) => { + // Skip star imports since we should never override their import alias + if (reference instanceof StarImport) { + return; + } + const name = reference.alias ?? reference.name; const fullyQualifiedModulePath = reference.getFullyQualifiedModulePath(); diff --git a/generators/python-v2/ast/src/__test__/PythonFile.test.ts b/generators/python-v2/ast/src/__test__/PythonFile.test.ts index feedb3d4313..4cfac924fc5 100644 --- a/generators/python-v2/ast/src/__test__/PythonFile.test.ts +++ b/generators/python-v2/ast/src/__test__/PythonFile.test.ts @@ -303,7 +303,10 @@ describe("PythonFile", () => { const file = python.file({ path: ["root"], comments: [python.comment({ docs: "flake8: noqa: F401, F403" })], - imports: [python.starImport({ modulePath: ["root", "my_module"] })], + imports: [ + python.starImport({ modulePath: ["root", "my_module_a"] }), + python.starImport({ modulePath: ["root", "my_module_b"] }) + ], statements: [ python.field({ name: "my_id", @@ -314,7 +317,7 @@ describe("PythonFile", () => { file.write(writer); expect(await writer.toStringFormatted()).toMatchSnapshot(); - expect(file.getReferences()).toHaveLength(2); + expect(file.getReferences()).toHaveLength(3); }); it("Write duplicative import names", async () => { diff --git a/generators/python-v2/ast/src/__test__/__snapshots__/PythonFile.test.ts.snap b/generators/python-v2/ast/src/__test__/__snapshots__/PythonFile.test.ts.snap index b4df0b363f9..68b01d373f2 100644 --- a/generators/python-v2/ast/src/__test__/__snapshots__/PythonFile.test.ts.snap +++ b/generators/python-v2/ast/src/__test__/__snapshots__/PythonFile.test.ts.snap @@ -131,7 +131,8 @@ exports[`PythonFile > Write star imports 1`] = ` "# flake8: noqa: F401, F403 from uuid import UUID -from .my_module import * +from .my_module_a import * +from .my_module_b import * my_id = UUID("1234") "