yanyongyu / githubkit

The modern, all-batteries-included GitHub SDK for Python, including rest api, graphql, webhooks, like octokit!
MIT License
158 stars 21 forks source link

Some typing classes are not public #106

Closed FeodorFitsner closed 3 weeks ago

FeodorFitsner commented 1 month ago

Thanks for the great library - it's async and typed!

While using some of the API methods, for example github.rest.pulls.async_create_review() I noticed it's signature requires ReposOwnerRepoPullsPullNumberReviewsPostBody which I was unable to import:

image

I imported and used ReposOwnerRepoPullsPullNumberReviewsPostBody instead and review was successfully added.

Am I using it wrongfully or there is a bug?

yanyongyu commented 1 month ago

The type ReposOwnerRepoPullsPullNumberReviewsPostBodyType is actually a TypedDict, you could simply pass python dict as the argument. The IDE could detect the TypedDict and prompt you the field name, check the field value type.

Import the TypedDict will cause extra memory usage, but, you can still import it from the types module:

from githubkit.versions.latest.types import ReposOwnerRepoPullsPullNumberReviewsPostBodyType
FeodorFitsner commented 4 weeks ago

Yep, that worked. Thanks!

...though using strings instead of parameters is not so elegant :)

Would it make sense to export those classes from a module?

yanyongyu commented 4 weeks ago

though using strings instead of parameters is not so elegant

I'm not sure how you are using the strings? you can just pass dicts or lists likes data={"body": "xxx", "comments": []}

Would it make sense to export those classes from a module?

The types can be actually imported from the types module i mentioned above:

from githubkit.versions.latest.types import ReposOwnerRepoPullsPullNumberReviewsPostBodyType
FeodorFitsner commented 3 weeks ago

Yep, this is how I'm using it and it works:

        await github.rest.pulls.async_create_review(
            owner="owner",
            repo="repo",
            pull_number=1,
            data={
                "body": "Alright, this is my review!",
                "event": "COMMENT",
                "comments": [
                    {
                        "path": "docs/tutorials/python-todo.md",
                        "body": "1st suggestion...\n\n```suggestion\nPar 1...\n```\n",
                        "line": 136,
                    },
                ],
            },
yanyongyu commented 3 weeks ago

If there is any other questions, feel free to open an issue. i will close this.