Skip to content

Add type arguments for generic classes #1105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nanewalt opened this issue Apr 16, 2025 · 3 comments · Fixed by #1110
Closed

Add type arguments for generic classes #1105

nanewalt opened this issue Apr 16, 2025 · 3 comments · Fixed by #1110

Comments

@nanewalt
Copy link

Chore

Update client methods to mirror postgrest return type hints

Describe the chore

Methods in both sync & async clients specify generic return types without type arguments, resulting in linter warnings.

def from_(self, table_name: str) -> SyncRequestBuilder:
        """Perform a table operation.

        See the `table` method.
        """
        return self.postgrest.from_(table_name)
query = supabase.from_("foo")    # Type of "from_" is "(table_name: str) -> SyncRequestBuilder[Unknown]" [reportUnknownMemberType]

Even with type hinting on the variable, we get a similar error

class Foo(BaseModel):
    ...

foos: list[Foo] = supabase.from_("foo").select("*").execute().data  # Type of "data" is "List[Unknown]" [reportUnknownMemberType]

The underlying postgrest methods do specify type arguments, but this is hidden behind the type hints in the supabase client. There seem to be two possible resolutions here:

  1. Remove type hints from methods in the supabase clients and allow underlying postgrest type hints to propagate
def from_(self, table_name: str):
    ...
  1. Add type arguments to existing generic return types in the supabase clients
_ReturnType = TypeVar("_ReturnType")

def from_(self, table_name: str) -> SyncRequestBuilder[_ReturnType]:
    ...

I tend to prefer option 1 since these methods are simple wrappers - if postgrest-py updates their return types in the future, why have the burden of updating those here as well?

Additional context

postgrest-py from_ method

@grdsdev
Copy link
Contributor

grdsdev commented Apr 23, 2025

@silentworks, what do you think about these suggestions?

@silentworks
Copy link
Contributor

I'm going to test this out and get back to you on this issue.

@silentworks
Copy link
Contributor

Yeah the issues stated by @nanewalt are correct. I've created a PR to fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants