Skip to content

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

Open

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.

Activity

  1. sornapudisuresh commented on Jul 29, 2026

    @sornapudisuresh

    I reproduced this on current master and would like to take it.

    Verified with clean Python containers:

    • Python 3.9: ImportError: cannot import name 'NotRequired' from 'typing'
    • Python 3.10: the same NotRequired import failure
    • Python 3.11: the current import succeeds

    Plan:

    1. Move NotRequired and TypeAlias to typing_extensions in the Python type generator while leaving the remaining imports in typing.
    2. Update the generated Python inline snapshot / focused generator assertions.
    3. Validate generated output imports under Python 3.9, 3.10, and a current Python version with Pydantic installed, then run the TypeScript check and relevant test suite.

    I’ll keep this scoped to generated-code compatibility and won’t add a new runtime dependency to postgres-meta itself.

  2. tushardev-365 commented on Jul 29, 2026

    @tushardev-365
    Author

    Go for it, glad it reproduced cleanly. If anything in the report is unclear while you build the fix, ping me here, happy to test the PR on 3.9 and 3.10.

  3. sornapudisuresh commented on Jul 29, 2026

    @sornapudisuresh

    Thanks @tushardev-365 — the PR is up: #1094

    CI is waiting on workflow approval for first-time contributors. Happy to address any feedback once the checks run. Also welcome a 3.9/3.10 smoke test on your side if you still have bandwidth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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