yanyongyu / githubkit

The modern, all-batteries-included GitHub SDK for Python, including rest api, graphql, webhooks, like octokit!
https://yanyongyu.github.io/githubkit/
MIT License
204 stars 25 forks source link

ImportError: cannot import name 'User' from 'githubkit.versions.latest.models' #119

Closed BhuwanPandey closed 4 months ago

BhuwanPandey commented 4 months ago

Is there anything that am I missing? What the reason that getting this error eventhough I have setup up githubkit in virtualenv well. with poetry add githubkit[auth-app]

file.py

from githubkit import GitHub
from githubkit.versions.latest.models import User

Error reproduce when run python file.py on Window 11 Python version 3.11 Poetry version 1.3.2

yanyongyu commented 4 months ago

which version of githubkit you are using? this may help me to locate the reason of this error.

yanyongyu commented 4 months ago

It seems the code example in the readme is outdated. GitHub has changed the model name of User into PrivateUser | PublicUser. I will update the examples in the readme.

yanyongyu commented 4 months ago

You can simply remove the type hint and you can see the inferred type of the return value from IDE.

BhuwanPandey commented 4 months ago

I have a question that Is this package allow to return authorize url like https://github.com/login/oauth/authorize?response_type=code&client_id=codeID&redirect_uri=REDIRECT_URL&scope=user+user%3Aemail

I am new to this package, when i visit readme section, may be i missed, I didnot get it.

yanyongyu commented 4 months ago

I have a question that Is this package allow to return authorize url like https://github.com/login/oauth/authorize?response_type=code&client_id=codeID&redirect_uri=REDIRECT_URL&scope=user+user%3Aemai

In the oauth flow, you should redirect user to the authorize page first. After user authorized your app, github will redirect user to your callback url. You can get the code from the callback url and give the code to githubkit to exchange access token.

In the flow above, you should handle the web related things by yourself, including redirect user to authorize and handle the callback from github. githubkit will use the code to exchange access_token and you can use the token to act as user.