From 8e9c13743e86fde6b46a5d07263d7f5bd0ce1747 Mon Sep 17 00:00:00 2001 From: "suresh.sornapudi" Date: Wed, 29 Jul 2026 19:02:05 +0530 Subject: [PATCH] fix: support Python 3.9 type generation --- src/server/templates/python.ts | 3 +-- test/server/templates/python.test.ts | 25 +++++++++++++++++++++++++ test/server/typegen.ts | 4 ++-- 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 test/server/templates/python.test.ts diff --git a/src/server/templates/python.ts b/src/server/templates/python.ts index 0d00f475..be37b9ae 100644 --- a/src/server/templates/python.ts +++ b/src/server/templates/python.ts @@ -40,11 +40,10 @@ from typing import ( Any, List, Literal, - NotRequired, Optional, - TypeAlias, TypedDict, ) +from typing_extensions import NotRequired, TypeAlias from pydantic import BaseModel, Field, Json diff --git a/test/server/templates/python.test.ts b/test/server/templates/python.test.ts new file mode 100644 index 00000000..ee4ccb0d --- /dev/null +++ b/test/server/templates/python.test.ts @@ -0,0 +1,25 @@ +import { expect, test } from 'vitest' + +import type { GeneratorMetadata } from '../../../src/lib/generators' +import { apply } from '../../../src/server/templates/python' + +const emptyMetadata: GeneratorMetadata = { + schemas: [], + tables: [], + foreignTables: [], + views: [], + materializedViews: [], + columns: [], + relationships: [], + functions: [], + types: [], +} + +test('imports compatibility typing helpers from typing_extensions', () => { + const result = apply(emptyMetadata) + const typingImport = result.match(/from typing import \(([\s\S]*?)\)/)?.[1] + + expect(typingImport).not.toContain('NotRequired') + expect(typingImport).not.toContain('TypeAlias') + expect(result).toContain('from typing_extensions import NotRequired, TypeAlias') +}) diff --git a/test/server/typegen.ts b/test/server/typegen.ts index 50a0896b..8cf07f26 100644 --- a/test/server/typegen.ts +++ b/test/server/typegen.ts @@ -6624,6 +6624,7 @@ test('typegen: python', async () => { path: '/generators/python', query: { access_control: 'public' }, }) + expect(body).toContain('from typing_extensions import NotRequired, TypeAlias') expect(body).toMatchInlineSnapshot(` "from __future__ import annotations @@ -6634,11 +6635,10 @@ test('typegen: python', async () => { Any, List, Literal, - NotRequired, Optional, - TypeAlias, TypedDict, ) + from typing_extensions import NotRequired, TypeAlias from pydantic import BaseModel, Field, Json