Skip to content

python typegen output fails to import on python 3.9 and 3.10 (NotRequired, TypeAlias from typing) #1088

Description

@tushardev-365

Title: python typegen output fails to import on python 3.9 and 3.10 (NotRequired, TypeAlias from typing)

Bug

The python template (src/server/templates/python.ts) generates this import block:

from typing import (
    Annotated,
    Any,
    List,
    Literal,
    NotRequired,
    Optional,
    TypeAlias,
    TypedDict,
)

typing.NotRequired only exists since python 3.11 and typing.TypeAlias since 3.10, so the generated file crashes on import for anyone on 3.9 or 3.10:

ImportError: cannot import name 'NotRequired' from 'typing'

supabase-py supports python >= 3.9, so the generated types are unusable on two supported versions. Hit this on python 3.10.11 with types generated by supabase gen types --lang=python --local (CLI 2.109.1) while following https://supabase.com/docs/guides/api/rest/generating-python-types.

Suggested fix

Import both names from typing_extensions instead. The generated code already depends on pydantic, and pydantic depends on typing_extensions, so this adds no new requirement for users:

from typing import Annotated, Any, List, Literal, Optional, TypedDict
from typing_extensions import NotRequired, TypeAlias

(typing_extensions re-exports these on newer pythons too, so this is safe across all supported versions.)

Happy to send a PR for the template if that helps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions