-
Notifications
You must be signed in to change notification settings - Fork 961
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
Add type annotations for Spotify JSON objects #695
base: v3
Are you sure you want to change the base?
Conversation
"expires_in": int, | ||
"refresh_token": str, | ||
"expires_at": int | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scope
and refresh_token
will not be present for the client credentials flow, and so they should be optional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future we could look into creating a new type if possible, but probably not a worry now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I discussed this here. We can either:
- Ignore the fact that they will not be present
- Create a class
TokenInfo
- Remove this, use
Dict[str, Any]
, and wait untilTypeDict
supports optional keys (or just forget it)
spotipy/json_types.py
Outdated
"total": int, | ||
}) | ||
|
||
PrivateUser = TypedDict("PrivateUser", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The email
, explicit_content
, product
, and country
properties of the PrivateUser
object can still be nil
if certain scopes are missing, and so these should also be optional. See here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is the same issue that I described here.
Working on #439. It is WIP but I would like some feedback before I validate the return types one by one.
All public methods are annotated. I haven't added anything that alters the runtime behavior in any way.
The arguments are straightforward since they are all basic types, but I had to define new types for the return values. The alternative is using
Dict[str, Any]
for all the JSON dicts, which would be more "lightweight" but provides near-zero typing information.It works on nearly examples!