Skip to content

Type checking error when using github.paginate #27

Open
@netomi

Description

@netomi

When trying to use the paginate function like that:

org_id = "blabla"
github = GitHub("token")
for repo in github.paginate(github.rest.repos.list_for_org, org=org_id):
    print(repo)

I get the following type checking error in PyCharm 2023.1:

Unexpected type(s): ((org: str, type: Literal["all", "public", "private", "forks", "sources", "member"] | Unset, sort: Literal["created", "updated", "pushed", "full_name"] | Unset, direction: Literal["asc", "desc"] | Unset, per_page: Unset | int, page: Unset | int) -> Response[list[MinimalRepository]]) Possible type(s): ((org: str, type: Literal["all", "public", "private", "forks", "sources", "member"] | Unset, sort: Literal["created", "updated", "pushed", "full_name"] | Unset, direction: Literal["asc", "desc"] | Unset, per_page: Unset | int, page: Unset | int) -> Response | (org: str, type: Literal["all", "public", "private", "forks", "sources", "member"] | Unset, sort: Literal["created", "updated", "pushed", "full_name"] | Unset, direction: Literal["asc", "desc"] | Unset, per_page: Unset | int, page: Unset | int) -> Awaitable[Response]) ((org: str, type: Literal["all", "public", "private", "forks", "sources", "member"] | Unset, sort: Literal["created", "updated", "pushed", "full_name"] | Unset, direction: Literal["asc", "desc"] | Unset, per_page: Unset | int, page: Unset | int) -> Response | (org: str, type: Literal["all", "public", "private", "forks", "sources", "member"] | Unset, sort: Literal["created", "updated", "pushed", "full_name"] | Unset, direction: Literal["asc", "desc"] | Unset, per_page: Unset | int, page: Unset | int) -> Awaitable[Response])

running it works though.

I could fix that error, changing the following code (there are 3 overriden paginate methods, I did change all of them accordingly):

    @staticmethod
    def paginate(
        request: R[CP, CT],
        page: int = 1,
        per_page: int = 100,
        map_func: Optional[Callable[[Response[CT]], List[RT]]] = None,
        *args: CP.args,
        **kwargs: CP.kwargs,
    ) -> Paginator[RT]:
        return Paginator(request, page, per_page, map_func, *args, **kwargs)  # type: ignore

to

    @staticmethod
    def paginate(
        request: R,
        page: int = 1,
        per_page: int = 100,
        map_func: Optional[Callable[[Response[CT]], List[RT]]] = None,
        *args: CP.args,
        **kwargs: CP.kwargs,
    ) -> Paginator[RT]:
        return Paginator(request, page, per_page, map_func, *args, **kwargs)  # type: ignore

so not providing type arguments to R itself, which is not clear to me why this even works as R is not a generic type imho.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy