Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/server/templates/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 25 additions & 0 deletions test/server/templates/python.test.ts
Original file line number Diff line number Diff line change
@@ -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')
})
4 changes: 2 additions & 2 deletions test/server/typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down