Skip to content

_TableT is not compatible with TypedDict #596

@Glinte

Description

@Glinte

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

from ..version import __version__
from .request_builder import AsyncRequestBuilder, AsyncRPCFilterRequestBuilder
_TableT = Dict[str, Any]
class AsyncPostgrestClient(BasePostgrestClient):

_TableT should be MutableMapping[str, Any] (Edit: Mapping[str, Any]) instead of dict[str, Any] to allow for users to specify a TypedDict as the output type. This seems to be a new-ish regression because my type checker wasn't complaining 4 months ago (edit: this is because there was no _TableT in postgrest 0.19.3 )

Issues from the two main type checkers explaining why dict is not compatible with TypedDict by design
mypy: python/mypy#4976
pyright: microsoft/pyright#6658

To Reproduce

Image

async def f():
    db = AsyncClient(supabase_url, supabase_key, options)
    response: APIResponse[MessageRecord] = await db.table("messages").select("*").execute()

class MessageRecord(TypedDict):
    content: str | None

Expected behavior

Using a TypedDict should be accepted

System information

  • OS: Windows
  • postgrest-py: 1.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions